2022-12-13 15:39:44 -05:00
// Module included in the following assembly:
//
2024-05-07 14:34:17 +05:30
// * hosted_control_planes/hcp_high_availability/hcp-backup-restore-aws.adoc
2022-12-13 15:39:44 -05:00
2023-10-30 10:13:25 -04:00
:_mod-docs-content-type: PROCEDURE
2022-12-13 15:39:44 -05:00
[id="backup-etcd-hosted-cluster_{context}"]
2024-05-07 14:34:17 +05:30
= Taking a snapshot of etcd for a hosted cluster
2022-12-13 15:39:44 -05:00
2024-05-07 14:34:17 +05:30
To back up etcd for a hosted cluster, you must take a snapshot of etcd. Later, you can restore etcd by using the snapshot.
2022-12-13 15:39:44 -05:00
[IMPORTANT]
====
This procedure requires API downtime.
====
.Procedure
2024-05-07 14:34:17 +05:30
. Pause reconciliation of the hosted cluster by entering the following command:
2022-12-13 15:39:44 -05:00
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc patch -n clusters hostedclusters/<hosted_cluster_name> \
-p '{"spec":{"pausedUntil":"true"}}' --type=merge
2022-12-13 15:39:44 -05:00
----
2024-05-07 14:34:17 +05:30
. Stop all etcd-writer deployments by entering the following command:
2022-12-13 15:39:44 -05:00
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc scale deployment -n <hosted_cluster_namespace> --replicas=0 \
kube-apiserver openshift-apiserver openshift-oauth-apiserver
2022-12-13 15:39:44 -05:00
----
2024-05-07 14:34:17 +05:30
. To take an etcd snapshot, use the `exec` command in each etcd container by entering the following command:
2022-12-13 15:39:44 -05:00
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ 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
2024-04-17 13:50:00 +05:30
----
. To check the snapshot status, use the `exec` command in each etcd container by running the following command:
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc exec -it <etcd_pod_name> -n <hosted_cluster_namespace> -- \
env ETCDCTL_API=3 /usr/bin/etcdctl -w table snapshot status \
/var/lib/data/snapshot.db
2022-12-13 15:39:44 -05:00
----
2024-05-07 14:34:17 +05:30
. Copy the snapshot data to a location where you can retrieve it later, such as an S3 bucket. See the following example.
2022-12-13 15:39:44 -05:00
+
[NOTE]
====
2024-05-07 14:34:17 +05:30
The following example uses signature version 2. If you are in a region that supports signature version 4, such as the `us-east-2` region, use signature version 4. Otherwise, when copying the snapshot to an S3 bucket, the upload fails.
2022-12-13 15:39:44 -05:00
====
+
.Example
[source,terminal]
----
BUCKET_NAME=somebucket
2025-01-15 12:11:08 -05:00
CLUSTER_NAME=cluster_name
2022-12-13 15:39:44 -05:00
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=accesskey
SECRET_KEY=secret
SIGNATURE_HASH=`echo -en ${SIGNATURE_STRING} | openssl sha1 -hmac ${SECRET_KEY} -binary | base64`
2025-01-15 12:11:08 -05:00
HOSTED_CLUSTER_NAMESPACE=hosted_cluster_namespace
2022-12-13 15:39:44 -05:00
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
----
2024-05-07 14:34:17 +05:30
. 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:
2022-12-13 15:39:44 -05:00
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc get hostedcluster <hosted_cluster_name> \
-o=jsonpath='{.spec.secretEncryption.aescbc}'
2024-05-07 14:34:17 +05:30
{"activeKey":{"name":"<hosted_cluster_name>-etcd-encryption-key"}}
----
2022-12-13 15:39:44 -05:00
2024-05-07 14:34:17 +05:30
.. Save the secret encryption key by entering the following command:
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc get secret <hosted_cluster_name>-etcd-encryption-key \
-o=jsonpath='{.data.key}'
2022-12-13 15:39:44 -05:00
----
2024-05-07 14:34:17 +05:30
+
You can decrypt this key when restoring a snapshot on a new cluster.
2022-12-13 15:39:44 -05:00
2025-01-15 12:11:08 -05:00
. Restart all etcd-writer deployments by entering the following command:
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc scale deployment -n <control_plane_namespace> --replicas=3 \
kube-apiserver openshift-apiserver openshift-oauth-apiserver
2025-01-15 12:11:08 -05:00
----
. Resume the reconciliation of the hosted cluster by entering the following command:
+
[source,terminal]
----
2025-03-17 08:42:39 +01:00
$ oc patch -n <hosted_cluster_namespace> \
-p '[\{"op": "remove", "path": "/spec/pausedUntil"}]' --type=json
2025-01-15 12:11:08 -05:00
----
2022-12-13 15:39:44 -05:00
.Next steps
2025-01-15 12:11:08 -05:00
Restore the etcd snapshot.