Backing up and restoring etcd on the management cluster¶
You can back up and restore etcd on the management cluster to fix failures.
Taking a snapshot of etcd for a hosted cluster¶
To back up etcd for a hosted cluster, you must take a snapshot of etcd. Later, you can restore etcd by using the snapshot.
Procedure
-
Stop all etcd-writer deployments by entering the following command:
-
To take an etcd snapshot, use the
execcommand in the etcd container by entering the following command:$ oc exec -it <etcd_pod_name> -n <hosted_cluster_namespace> -- \ env ETCDCTL_API=3 /usr/bin/etcdctl \ --cacert /etc/etcd/tls/etcd-ca/ca.crt \ --cert /etc/etcd/tls/client/etcd-client.crt \ --key /etc/etcd/tls/client/etcd-client.key \ --endpoints=localhost:2379 \ snapshot save /var/lib/data/snapshot.db -
To check the snapshot status, use the
execcommand in the etcd container by running the following command: -
Copy the snapshot data to a location where you can retrieve it later, such as an S3 bucket. See the following example.
Note
The following example uses signature version 2. If you are in a region that supports signature version 4, such as the
us-east-2region, use signature version 4. Otherwise, when copying the snapshot to an S3 bucket, the upload fails.ExampleBUCKET_NAME=somebucket CLUSTER_NAME=cluster_name FILEPATH="/${BUCKET_NAME}/${CLUSTER_NAME}-snapshot.db" CONTENT_TYPE="application/x-compressed-tar" DATE_VALUE=`date -R` SIGNATURE_STRING="PUT\n\n${CONTENT_TYPE}\n${DATE_VALUE}\n${FILEPATH}" ACCESS_KEY=<access_key> SECRET_KEY=<secret> SIGNATURE_HASH=`echo -en ${SIGNATURE_STRING} | openssl sha1 -hmac ${SECRET_KEY} -binary | base64` HOSTED_CLUSTER_NAMESPACE=hosted_cluster_namespace $ oc exec -it etcd-0 -n ${HOSTED_CLUSTER_NAMESPACE} -- curl -X PUT -T "/var/lib/data/snapshot.db" \ -H "Host: ${BUCKET_NAME}.s3.amazonaws.com" \ -H "Date: ${DATE_VALUE}" \ -H "Content-Type: ${CONTENT_TYPE}" \ -H "Authorization: AWS ${ACCESS_KEY}:${SIGNATURE_HASH}" \ https://${BUCKET_NAME}.s3.amazonaws.com/${CLUSTER_NAME}-snapshot.db -
To restore the snapshot on a new cluster later, save the encryption secret that the hosted cluster references.
-
Get the secret encryption key by entering the following command:
-
Save the secret encryption key by entering the following command:
$ oc get -n <hosted_cluster_namespace> secret <hosted_cluster_name>-etcd-encryption-key \ -o=jsonpath='{.data.key}'You can decrypt this key when restoring a snapshot on a new cluster.
-
-
Restart all etcd-writer deployments by entering the following command:
Next steps
Restore the etcd snapshot.
Restoring an etcd snapshot on a hosted cluster¶
If you have a snapshot of etcd from your hosted cluster, you can restore it. Currently, you can restore an etcd snapshot only during cluster creation.
To restore an etcd snapshot, you change the output from the create cluster --render command and define a restoreSnapshotURL value in the etcd section of the HostedCluster specification.
Warning
If the snapshot that you are restoring is from a hosted cluster with LoadBalancer services, the load balancer IPs might no longer be valid. In that case, you must delete and re-create the LoadBalancer services.
Prerequisites
- You took an etcd snapshot on a hosted cluster.
Procedure
-
Delete the hosted cluster that you backed up in "Taking a snapshot of etcd for a hosted cluster" by entering the following command:
-
On the
awscommand-line interface (CLI), create a pre-signed URL so that you can download your etcd snapshot from S3 without passing credentials to the etcd deployment:-
Define the snapshot by entering the following command:
-
Define the snapshot URL by entering the following command:
-
-
Create the new hosted cluster by entering the following command:
$ hcp create cluster <platform> \ --name <hosted_cluster_name> \ --namespace <hosted_cluster_namespace> \ --node-pool-replicas=2 \ --node-upgrade-type=Replace \ --pull-secret <path_to_pull_secret> \ --memory <value_for_memory> \ --cores <value_for_cpu> \ --etcd-storage-class=gp3-csi \ --release-image=<release_image_reference> \ --etcd-storage-size=8Gi \ --fips=false \ --render \ --render-sensitive-
<hosted_cluster_name>specifies the name of the new hosted cluster. The name of the new cluster must be identical to the name of the cluster from which the etcd backup was taken. -
<platform>specifies the platform you are creating the hosted cluster on, such askubevirtoraws. -
<hosted_cluster_namespace>specifies the namespace where you are creating the hosted cluster. -
<path_to_pull_secret>specifies the path to your pull secret; for example,/user/name/pullsecret. -
<value_for_memory>specifies the memory value, such as8Gi. -
<value_for_cpu>specifies the CPU value, such as2. -
<release_image_reference>specifies the OpenShift Container Platform release image for the cluster, for example,quay.io/openshift-release-dev/ocp-release:4.20.14-multi. You can use the--release-imageflag to set up the hosted cluster with a specific OpenShift Container Platform release.Note
The
--renderflag in thehcp createcommand does not render the secrets. To render the secrets, you must use both the--renderand the--render-sensitiveflags in thehcp createcommand.Example outputapiVersion: v1 kind: Namespace metadata: name: <hosted_cluster_namespace> spec: {} status: {} --- apiVersion: v1 data: .dockerconfigjson: <path_to_pull_secret> kind: Secret metadata: labels: hypershift.openshift.io/safe-to-delete-with-cluster: "true" name: <hosted_cluster_name_pull_secret> namespace: <hosted_cluster_namespace> --- apiVersion: hypershift.openshift.io/v1beta1 kind: HostedCluster metadata: name: <hosted_cluster_name> namespace: <hosted_cluster_namespace> spec: autoscaling: {} capabilities: {} configuration: {} controllerAvailabilityPolicy: HighlyAvailable dns: baseDomain: "" etcd: managed: storage: persistentVolume: size: 8Gi storageClassName: gp3-csi type: PersistentVolume managementType: Managed fips: false infraID: <hosted_cluster_name>-68tlg infrastructureAvailabilityPolicy: HighlyAvailable networking: clusterNetwork: - cidr: 10.132.0.0/14 networkType: OVNKubernetes serviceNetwork: - cidr: 172.31.0.0/16 olmCatalogPlacement: guest platform: kubevirt: baseDomainPassthrough: true type: KubeVirt pullSecret: name: <hosted_cluster_name_pull_secret> release: image: quay.io/openshift-release-dev/ocp-release:4.21.12-multi services: - service: APIServer servicePublishingStrategy: type: LoadBalancer - service: Ignition servicePublishingStrategy: type: Route - service: Konnectivity servicePublishingStrategy: type: Route - service: OAuthServer servicePublishingStrategy: type: Route sshKey: {} status: controlPlaneEndpoint: host: "" port: 0 --- apiVersion: hypershift.openshift.io/v1beta1 kind: NodePool metadata: name: <hosted_cluster_name> namespace: <hosted_cluster_namespace> spec: arch: amd64 clusterName: <hosted_cluster_name> management: autoRepair: false upgradeType: Replace nodeDrainTimeout: 0s nodeVolumeDetachTimeout: 0s platform: kubevirt: attachDefaultNetwork: true compute: cores: 2 memory: 8Gi networkInterfaceMultiqueue: Enable rootVolume: persistent: size: 32Gi type: Persistent type: KubeVirt release: image: quay.io/openshift-release-dev/ocp-release:<4.x.x>-multi replicas: 2 status: replicas: 0 -
<hosted_cluster_namespace>specifies the name of the hosted cluster namespace. -
<path_to_pull_secret>specifies the path to the pull secret. -
<hosted_cluster_name_pull_secret>specifies the name of the restored pull secret for the new hosted cluster. -
<hosted_cluster_name>specifies the name of the new hosted cluster. The name of the new cluster must be identical to the name of the cluster from which the etcd backup was taken. -
<4.x.x>specifies the version of the release image.
-
-
Change the
HostedClusterspecification to refer to the URL: -
Change the
HostedClusterspecification to include the new etcd encryption key:apiVersion: v1 data: key: <pre_generated_etcd_encryption_key> kind: Secret metadata: labels: hypershift.openshift.io/safe-to-delete-with-cluster: "true" name: <new_hc_etcd_encryption_key> namespace: <hosted_cluster_namespace> type: Opaque --- spec: secretEncryption: aescbc: activeKey: name: <new_hc_etcd_encryption_key> type: aescbc<pre_generated_etcd_encryption_key>specifies the etcd encryption key of original hosted cluster.<new_hc_etcd_encryption_key>specifies the etcd encryption key of the new hosted cluster. Ensure that the secret that you referenced from thespec.secretEncryption.aescbcvalue has the same Advanced Encryption Standard (AES) key that you saved earlier.
Verification
-
To verify that the snapshot was restored, enter the following command:
If you use a high availability deployment, you can also check the
etcd-1andetcd-2containers.