docs: add scripts, details, and new steps to CRD restoration guide

Signed-off-by: Alexander Bauer <sasha@linux.com>
(cherry picked from commit 825e956849)
This commit is contained in:
Alexander Bauer authored and Mergify committed 2022-10-21 14:14:10 +00:00
1 parent 2637eec97d
commit e88bdffc70
1 file changed
+84 -38
@@ -40,7 +40,6 @@ the CRs to their prior state without even necessarily suffering cluster downtime
In the following commands, the affected `CephCluster` resource is called `rook-ceph`. If yours is named differently, the
commands will need to be adjusted.
1. Scale down the operator.
```console
@@ -50,7 +49,7 @@ the CRs to their prior state without even necessarily suffering cluster downtime
2. Backup all Rook CRs and critical metadata
```console
# Store the CephCluster CR settings. Also, save other Rook CRs that are in terminating state.
# Store the `CephCluster` CR settings. Also, save other Rook CRs that are in terminating state.
kubectl -n rook-ceph get cephcluster rook-ceph -o yaml > cluster.yaml
# Backup critical secrets and configmaps in case something goes wrong later in the procedure
@@ -58,65 +57,112 @@ the CRs to their prior state without even necessarily suffering cluster downtime
kubectl -n rook-ceph get configmap -o yaml > configmaps.yaml
```
3. Remove the owner references from all critical Rook resources that were referencing the CephCluster CR.
The critical resources include:
3. Back up and remove the `ValidatingWebhookConfiguration`. This is the resource which connects Rook custom resources to the
operator pod's validating webhook. Because the operator is unavailable, we must temporarily disable the valdiating webhook in
order to make changes.
- Secrets: `rook-ceph-admin-keyring`, `rook-ceph-config`, `rook-ceph-mon`, `rook-ceph-mons-keyring`
- ConfigMap: `rook-ceph-mon-endpoints`
- Services: `rook-ceph-mon-*`, `rook-ceph-mgr-*`
- Deployments: `rook-ceph-mon-*`, `rook-ceph-osd-*`, `rook-ceph-mgr-*`
- PVCs (if applicable): `rook-ceph-mon-*` and the OSD PVCs (named `<deviceset>-*`, for example `set1-data-*`)
1. Save the `ValidatingWebhookConfiguration` responsible for controlling Rook resources. (These are not namespaced
resources.)
For example, remove this entire block from each resource:
```console
kubectl get ValidatingWebhookConfiguration rook-ceph-webhook -o yaml > rook-ceph-webhook.yaml
```
```yaml
ownerReferences:
- apiVersion: ceph.rook.io/v1
blockOwnerDeletion: true
controller: true
kind: CephCluster
name: rook-ceph
uid: <uid>
```
2. Delete the `ValidatingWebhookConfiguration`.
4. **After confirming all critical resources have had the owner reference to the CephCluster CR removed**, now
we allow the cluster CR to be deleted. Remove the finalizer by editing the CephCluster CR.
```console
kubectl delete ValidatingWebhookConfiguration rook-ceph-webhook
```
4. Remove the owner references from all critical Rook resources that were referencing the `CephCluster` CR.
1. Programmatically determine all such resources, using this command:
```console
# Determine the `CephCluster` UID
ROOK_UID=$(kubectl -n rook-ceph get cephcluster rook-ceph -o 'jsonpath={.metadata.uid}')
# List all secrets, configmaps, services, deployments, and PVCs with that ownership UID.
RESOURCES=$(kubectl -n rook-ceph get secret,configmap,service,deployment,pvc -o jsonpath='{range .items[?(@.metadata.ownerReferences[*].uid=="'"$ROOK_UID"'")]}{.kind}{"/"}{.metadata.name}{"\n"}{end}')
# Show the collected resources.
kubectl -n rook-ceph get $RESOURCES
```
2. **Verify that all critical resources are shown in the output.** The critical resources are these:
- Secrets: `rook-ceph-admin-keyring`, `rook-ceph-config`, `rook-ceph-mon`, `rook-ceph-mons-keyring`
- ConfigMap: `rook-ceph-mon-endpoints`
- Services: `rook-ceph-mon-*`, `rook-ceph-mgr-*`
- Deployments: `rook-ceph-mon-*`, `rook-ceph-osd-*`, `rook-ceph-mgr-*`
- PVCs (if applicable): `rook-ceph-mon-*` and the OSD PVCs (named `<deviceset>-*`, for example `set1-data-*`)
3. For each listed resource, remove the `ownerReferences` metadata field, in order to unlink it from the deleting `CephCluster`
CR.
To do so programmatically, use the command:
```console
for resource in $(kubectl -n rook-ceph get $RESOURCES -o name); do
kubectl -n rook-ceph patch $resource -p '{"metadata": {"ownerReferences":null}}'
done
```
For a manual alternative, issue `kubectl edit` on each resource, and remove the block matching:
```yaml
ownerReferences:
- apiVersion: ceph.rook.io/v1
blockOwnerDeletion: true
controller: true
kind: `CephCluster`
name: rook-ceph
uid: <uid>
```
5. **Before completing this step, validate these things. Failing to do so could result in data loss.**
1. Confirm that `cluster.yaml` contains the `CephCluster` CR.
2. Confirm all critical resources listed above have had the `ownerReference` to the `CephCluster` CR removed.
Remove the finalizer from the `CephCluster` resource. This will cause the resource to be immediately deleted by Kubernetes.
```console
kubectl -n rook-ceph edit cephcluster
kubectl -n rook-ceph patch cephcluster/rook-ceph --type json --patch='[ { "op": "remove", "path": "/metadata/finalizers" } ]'
```
For example, remove the following from the CR metadata:
```yaml
finalizers:
- cephcluster.ceph.rook.io
```
After the finalizer is removed, the CR will be immediately deleted. If all owner references were properly removed,
After the finalizer is removed, the `CephCluster` will be immediately deleted. If all owner references were properly removed,
all ceph daemons will continue running and there will be no downtime.
5. Create the CephCluster CR with the same settings as previously
6. Create the `CephCluster` CR with the same settings as previously
```console
# Use the same cluster settings as exported above in step 2.
# Use the same cluster settings as exported in step 2.
kubectl create -f cluster.yaml
```
6. If there are other CRs in terminating state such as CephBlockPools, CephObjectStores, or CephFilesystems,
7. If there are other CRs in terminating state such as CephBlockPools, CephObjectStores, or CephFilesystems,
follow the above steps as well for those CRs:
- Backup the CR
- Remove the finalizer and confirm the CR is deleted (the underlying Ceph resources will be preserved)
- Create the CR again
1. Backup the CR
2. Remove the finalizer and confirm the CR is deleted (the underlying Ceph resources will be preserved)
3. Create the CR again
7. Scale up the operator
8. Restore the `ValidatingWebhookConfiguration`.
```console
kubectl create -f rook-ceph-webhook.yaml
```
9. Scale up the operator
```console
kubectl -n rook-ceph scale --replicas=1 deploy/rook-ceph-operator
```
Watch the operator log to confirm that the reconcile completes successfully.
10. Watch the operator log to confirm that the reconcile completes successfully.
```console
kubectl -n rook-ceph logs -f deployment/rook-ceph-operator
```
## Adopt an existing Rook Ceph cluster into a new Kubernetes cluster