RBD Mirroring
Disaster Recovery¶
Disaster recovery (DR) is an organization's ability to react to and recover from an incident that negatively affects business operations. This plan comprises strategies for minimizing the consequences of a disaster, so an organization can continue to operate – or quickly resume the key operations. Thus, disaster recovery is one of the aspects of business continuity. One of the solutions, to achieve the same, is RBD mirroring.
RBD Mirroring¶
RBD mirroring is an asynchronous replication of RBD images between multiple Ceph clusters. This capability is available in two modes:
- Journal-based: Every write to the RBD image is first recorded to the associated journal before modifying the actual image. The remote cluster will read from this associated journal and replay the updates to its local image.
- Snapshot-based: This mode uses periodically scheduled or manually created RBD image mirror-snapshots to replicate crash-consistent RBD images between clusters.
Note
This document sheds light on rbd mirroring and how to set it up using rook. See also the topic on Failover and Failback
Create RBD Pools¶
In this section, we create specific RBD pools that are RBD mirroring enabled for use with the DR use case.
Execute the following steps on each peer cluster to create mirror enabled pools:
-
Create a RBD pool that is enabled for mirroring by adding the section
spec.mirroring
in the CephBlockPool CR: -
Repeat the steps on the peer cluster.
Note
Pool name across the cluster peers must be the same for RBD replication to function.
See the CephBlockPool documentation for more details.
Note
It is also feasible to edit existing pools and enable them for replication.
Bootstrap Peers¶
In order for the rbd-mirror daemon to discover its peer cluster, the peer must be registered and a user account must be created.
The following steps enable bootstrapping peers to discover and authenticate to each other:
- For Bootstrapping a peer cluster its bootstrap secret is required. To determine the name of the secret that contains the bootstrap secret execute the following command on the remote cluster (cluster-2)
Here, pool-peer-token-mirrored-pool
is the desired bootstrap secret name.
-
The secret pool-peer-token-mirrored-pool contains all the information related to the token and needs to be injected to the peer, to fetch the decoded secret:
-
With this Decoded value, create a secret on the primary site (cluster-1):
-
This completes the bootstrap process for cluster-1 to be peered with cluster-2.
- Repeat the process switching cluster-2 in place of cluster-1, to complete the bootstrap process across both peer clusters.
For more details, refer to the official rbd mirror documentation on how to create a bootstrap peer.
Configure the RBDMirror Daemon¶
Replication is handled by the rbd-mirror daemon. The rbd-mirror daemon is responsible for pulling image updates from the remote, peer cluster, and applying them to image within the local cluster.
Creation of the rbd-mirror daemon(s) is done through the custom resource definitions (CRDs), as follows:
-
Create mirror.yaml, to deploy the rbd-mirror daemon
-
Create the RBD mirror daemon
-
Validate if
rbd-mirror
daemon pod is now up -
Verify that daemon health is OK
-
Repeat the above steps on the peer cluster.
See the CephRBDMirror CRD for more details on the mirroring settings.
Add mirroring peer information to RBD pools¶
Each pool can have its own peer. To add the peer information, patch the already created mirroring enabled pool to update the CephBlockPool CRD.
Create VolumeReplication CRDs¶
Volume Replication Operator follows controller pattern and provides extended APIs for storage disaster recovery. The extended APIs are provided via Custom Resource Definition(CRD). Create the VolumeReplication CRDs on all the peer clusters.
Enable CSI Replication Sidecars¶
To achieve RBD Mirroring, csi-omap-generator
and csi-addons
containers need to be deployed in the RBD provisioner pods, which are not enabled by default.
-
Omap Generator: Omap generator is a sidecar container that when deployed with the CSI provisioner pod, generates the internal CSI omaps between the PV and the RBD image. This is required as static PVs are transferred across peer clusters in the DR use case, and hence is needed to preserve PVC to storage mappings.
-
Volume Replication Operator: Volume Replication Operator is a kubernetes operator that provides common and reusable APIs for storage disaster recovery. The volume replication operation is supported by the CSIAddons It is based on csi-addons/spec specification and can be used by any storage provider.
Execute the following steps on each peer cluster to enable the OMap generator and CSIADDONS sidecars:
-
Edit the
rook-ceph-operator-config
configmap and add the following configurationsAdd the following properties if not present:
-
After updating the configmap with those settings, two new sidecars should now start automatically in the CSI provisioner pod.
-
Repeat the steps on the peer cluster.
Volume Replication Custom Resources¶
VolumeReplication CRDs provide support for two custom resources:
-
VolumeReplicationClass: VolumeReplicationClass is a cluster scoped resource that contains driver related configuration parameters. It holds the storage admin information required for the volume replication operator.
-
VolumeReplication: VolumeReplication is a namespaced resource that contains references to storage object to be replicated and VolumeReplicationClass corresponding to the driver providing replication.
Enable mirroring on a PVC¶
Below guide assumes that we have a PVC (rbd-pvc) in BOUND state; created using StorageClass with Retain
reclaimPolicy.
Create a Volume Replication Class CR¶
In this case, we create a Volume Replication Class on cluster-1
Note
The schedulingInterval
can be specified in formats of minutes, hours or days using suffix m
, h
and d
respectively. The optional schedulingStartTime can be specified using the ISO 8601 time format.
Create a VolumeReplication CR¶
- Once VolumeReplicationClass is created, create a Volume Replication for the PVC which we intend to replicate to secondary cluster.
Note
VolumeReplication
is a namespace scoped object. Thus, it should be created in the same namespace as of PVC.
Checking Replication Status¶
replicationState
is the state of the volume being referenced. Possible values are primary, secondary, and resync.
primary
denotes that the volume is primary.secondary
denotes that the volume is secondary.resync
denotes that the volume needs to be resynced.
To check VolumeReplication CR status:
Backup & Restore¶
Note
To effectively resume operations after a failover/relocation, backup of the kubernetes artifacts like deployment, PVC, PV, etc need to be created beforehand by the admin; so that the application can be restored on the peer cluster.
Here, we take a backup of PVC and PV object on one site, so that they can be restored later to the peer cluster.
Take backup on cluster-1¶
- Take backup of the PVC
rbd-pvc
- Take a backup of the PV, corresponding to the PVC
Note
We can also take backup using external tools like Velero. See velero documentation for more information.
Restore the backup on cluster-2¶
- Create storageclass on the secondary cluster
- Create VolumeReplicationClass on the secondary cluster
- If Persistent Volumes and Claims are created manually on the secondary cluster, remove the
claimRef
on the backed up PV objects in yaml files; so that the PV can get bound to the new claim on the secondary cluster.
- Apply the Persistent Volume backup from the primary cluster
- Apply the Persistent Volume claim from the restored backup