Files
my-rook-config/Documentation/Storage-Configuration/ceph-teardown.md
T

207 lines
9.6 KiB
Markdown
Raw Normal View History

---
title: Cleanup
---
2024-04-02 19:26:45 +05:30
Rook provides the following clean up options:
1. [Uninstall: Clean up the entire cluster and delete all data](#cleaning-up-a-cluster)
2. [Force delete individual resources](#force-delete-resources)
2024-04-02 19:26:45 +05:30
2022-05-12 19:29:40 +02:00
## Cleaning up a Cluster
2019-10-24 10:22:08 +02:00
To tear down the cluster, the following resources need to be cleaned up:
2019-10-24 10:22:08 +02:00
* The resources created under Rook's namespace (default `rook-ceph`) such as the Rook operator created by `operator.yaml` and the cluster CR `cluster.yaml`.
* `/var/lib/rook/rook-ceph`: Path on each host in the cluster where configuration is stored by the ceph mons and osds
* Devices used by the OSDs
If the default namespaces or paths such as `dataDirHostPath` are changed in the example yaml files, these namespaces and paths will need to be changed throughout these instructions.
If tearing down a cluster frequently for development purposes, it is instead recommended to use an environment such as [Minikube](../Contributing/development-environment.md) that can easily be reset without worrying about any of these steps.
2022-05-12 19:29:40 +02:00
### Delete the Block and File artifacts
2019-10-24 10:22:08 +02:00
First clean up the resources from applications that consume the Rook storage.
These commands will clean up the resources from the example application [block](../Storage-Configuration/Block-Storage-RBD/block-storage.md#teardown) and [file](../Storage-Configuration/Shared-Filesystem-CephFS/filesystem-storage.md#teardown) walkthroughs (unmount volumes, delete volume claims, etc).
2019-10-24 10:22:08 +02:00
```console
2018-07-13 14:29:57 -06:00
kubectl delete -f ../wordpress.yaml
kubectl delete -f ../mysql.yaml
2018-12-03 23:48:40 -07:00
kubectl delete -n rook-ceph cephblockpool replicapool
kubectl delete storageclass rook-ceph-block
2019-08-01 16:31:50 -06:00
kubectl delete -f csi/cephfs/kube-registry.yaml
2019-12-04 10:16:14 +01:00
kubectl delete storageclass csi-cephfs
```
!!! important
After applications have been cleaned up, the Rook cluster can be removed. It is important to delete applications before removing the Rook operator and Ceph cluster. Otherwise, volumes may hang and nodes may require a restart.
2021-05-31 11:35:27 +05:30
2022-05-12 19:29:40 +02:00
### Delete the CephCluster CRD
2019-10-24 10:22:08 +02:00
!!! warning
DATA WILL BE PERMANENTLY DELETED AFTER DELETING THE `CephCluster`
2021-05-31 11:35:27 +05:30
1. To instruct Rook to wipe the host paths and volumes, edit the `CephCluster` and add the `cleanupPolicy`:
2021-05-31 11:35:27 +05:30
```console
kubectl -n rook-ceph patch cephcluster rook-ceph --type merge -p '{"spec":{"cleanupPolicy":{"confirmation":"yes-really-destroy-data"}}}'
```
2021-05-31 11:35:27 +05:30
Once the cleanup policy is enabled, any new configuration changes in the CephCluster will be blocked. Nothing will happen until the deletion of the CR is requested, so this `cleanupPolicy` change can still be reverted if needed.
2021-05-31 11:35:27 +05:30
Checkout more details about the `cleanupPolicy` [here](../CRDs/Cluster/ceph-cluster-crd.md#cleanup-policy)
2021-05-31 11:35:27 +05:30
2. Delete the `CephCluster` CR.
2019-10-24 10:22:08 +02:00
```console
kubectl -n rook-ceph delete cephcluster rook-ceph
```
3. Verify that the cluster CR has been deleted before continuing to the next step.
2019-10-24 10:22:08 +02:00
```console
kubectl -n rook-ceph get cephcluster
```
4. If the `cleanupPolicy` was applied, wait for the `rook-ceph-cleanup` jobs to be completed on all the nodes.
2021-05-31 11:35:27 +05:30
These jobs will perform the following operations:
* Delete the namespace directory under `dataDirHostPath`, for example `/var/lib/rook/rook-ceph`, on all the nodes
* Wipe the data on the drives on all the nodes where OSDs were running in this cluster
2021-05-31 11:35:27 +05:30
!!! note
The cleanup jobs might not start if the resources created on top of Rook Cluster are not deleted completely.
See [deleting block and file artifacts](#delete-the-block-and-file-artifacts)
2022-05-12 19:29:40 +02:00
### Delete the Operator Resources
2019-10-24 10:22:08 +02:00
Remove the Rook operator, RBAC, and CRDs, and the `rook-ceph` namespace.
2019-10-24 10:22:08 +02:00
```console
kubectl delete -f operator.yaml
kubectl delete -f common.yaml
kubectl delete -f crds.yaml
```
2022-05-12 19:29:40 +02:00
### Delete the data on hosts
2019-10-24 10:22:08 +02:00
2022-05-12 19:29:40 +02:00
!!! attention
The final cleanup step requires deleting files on each host in the cluster. All files under the `dataDirHostPath` property specified in the cluster CRD will need to be deleted. Otherwise, inconsistent state will remain when a new cluster is started.
If the `cleanupPolicy` was not added to the CephCluster CR before deleting the cluster, these manual steps are required to tear down the cluster.
Connect to each machine and delete the namespace directory under `dataDirHostPath`, for example `/var/lib/rook/rook-ceph`.
2022-05-12 19:29:40 +02:00
#### Zapping Devices
2020-04-01 15:21:03 -06:00
Disks on nodes used by Rook for OSDs can be reset to a usable state.
2022-02-17 13:00:07 -07:00
Note that these scripts are not one-size-fits-all. Please use them with discretion to ensure you are
not removing data unrelated to Rook.
2019-10-24 10:22:08 +02:00
A single disk can usually be cleared with some or all of the steps below.
2022-02-17 13:00:07 -07:00
2022-05-12 19:29:40 +02:00
```console
2022-02-17 13:00:07 -07:00
DISK="/dev/sdX"
# Zap the disk to a fresh, usable state (zap-all is important, b/c MBR has to be clean)
sgdisk --zap-all $DISK
2022-02-17 13:00:07 -07:00
# Wipe a large portion of the beginning of the disk to remove more LVM metadata that may be present
2020-04-01 15:21:03 -06:00
dd if=/dev/zero of="$DISK" bs=1M count=100 oflag=direct,dsync
2022-02-17 13:00:07 -07:00
# SSDs may be better cleaned with blkdiscard instead of dd
2020-06-11 15:35:28 -06:00
blkdiscard $DISK
2022-02-17 13:00:07 -07:00
# Inform the OS of partition table changes
partprobe $DISK
```
Ceph can leave LVM and device mapper data on storage drives, preventing them from being
redeployed. These steps can clean former Ceph drives for reuse. Note that this only needs to
be run once on each node. If you have **only one** Rook cluster and **all** Ceph disks are
being wiped, run the following command.
2022-02-17 13:00:07 -07:00
2022-05-12 19:29:40 +02:00
```console
2022-03-03 14:29:36 +00:00
# This command hangs on some systems: with caution, 'dmsetup remove_all --force' can be used
ls /dev/mapper/ceph-* | xargs -I% -- dmsetup remove %
# ceph-volume setup can leave ceph-<UUID> directories in /dev and /dev/mapper (unnecessary clutter)
rm -rf /dev/ceph-*
rm -rf /dev/mapper/ceph--*
```
2022-02-17 13:00:07 -07:00
If disks are still reported locked, rebooting the node often helps clear LVM-related holds on disks.
If there are multiple Ceph clusters and some disks are not wiped yet, it is necessary to manually
determine which disks map to which device mapper devices.
2022-05-12 19:29:40 +02:00
### Troubleshooting
2019-10-24 10:22:08 +02:00
The most common issue cleaning up the cluster is that the `rook-ceph` namespace or the cluster CRD remain indefinitely in the `terminating` state. A namespace cannot be removed until all of its resources are removed, so determine which resources are pending termination.
If a pod is still terminating, consider forcefully terminating the pod (`kubectl -n rook-ceph delete pod <name>`).
2019-10-24 10:22:08 +02:00
```console
kubectl -n rook-ceph get pod
```
2019-10-24 10:22:08 +02:00
If the cluster CRD still exists even though it has been deleted, see the next section on removing the finalizer.
2019-10-24 10:22:08 +02:00
```console
2018-12-03 23:48:40 -07:00
kubectl -n rook-ceph get cephcluster
```
2019-10-24 10:22:08 +02:00
2022-05-12 19:29:40 +02:00
#### Removing the Cluster CRD Finalizer
2019-10-24 10:22:08 +02:00
When a Cluster CRD is created, a [finalizer](https://kubernetes.io/docs/tasks/access-kubernetes-api/extend-api-custom-resource-definitions/#finalizers) is added automatically by the Rook operator. The finalizer will allow the operator to ensure that before the cluster CRD is deleted, all block and file mounts will be cleaned up. Without proper cleanup, pods consuming the storage will be hung indefinitely until a system reboot.
The operator is responsible for removing the finalizer after the mounts have been cleaned up.
If for some reason the operator is not able to remove the finalizer (i.e., the operator is not running anymore), delete the finalizer manually with the following command:
2019-10-24 10:22:08 +02:00
```console
2021-02-14 12:35:14 +01:00
for CRD in $(kubectl get crd -n rook-ceph | awk '/ceph.rook.io/ {print $1}'); do
kubectl get -n rook-ceph "$CRD" -o name | \
2022-08-26 12:55:01 +02:00
xargs -I {} kubectl patch -n rook-ceph {} --type merge -p '{"metadata":{"finalizers": []}}'
2021-02-14 12:35:14 +01:00
done
```
If the namespace is still stuck in Terminating state, check which resources are holding up the deletion and remove their finalizers as well:
```console
kubectl api-resources --verbs=list --namespaced -o name \
| xargs -n 1 kubectl get --show-kind --ignore-not-found -n rook-ceph
```
2022-05-12 19:29:40 +02:00
#### Remove critical resource finalizers
Rook adds a finalizer `ceph.rook.io/disaster-protection` to resources critical to the Ceph cluster so that the resources will not be accidentally deleted.
The operator is responsible for removing the finalizers when a CephCluster is deleted.
If the operator is not able to remove the finalizers (i.e., the operator is not running anymore), remove the finalizers manually:
```console
2022-08-26 12:55:01 +02:00
kubectl -n rook-ceph patch configmap rook-ceph-mon-endpoints --type merge -p '{"metadata":{"finalizers": []}}'
kubectl -n rook-ceph patch secrets rook-ceph-mon --type merge -p '{"metadata":{"finalizers": []}}'
```
2024-04-02 19:26:45 +05:30
## Force Delete Resources
To keep your data safe in the cluster, Rook disallows deleting critical cluster resources by default. To override this behavior and force delete a specific custom resource, add the annotation `rook.io/force-deletion="true"` to the resource and then delete it. Rook will start a cleanup job that will delete all the related ceph resources created by that custom resource.
For example, run the following commands to clean the `CephFilesystemSubVolumeGroup` resource named `my-subvolumegroup`
``` console
kubectl -n rook-ceph annotate cephfilesystemsubvolumegroups.ceph.rook.io my-subvolumegroup rook.io/force-deletion="true"
kubectl -n rook-ceph delete cephfilesystemsubvolumegroups.ceph.rook.io my-subvolumegroup
```
Once the cleanup job is completed successfully, Rook will remove the finalizers from the deleted custom resource.
This cleanup is supported only for the following custom resources:
2024-04-10 00:06:39 +05:30
| Custom Resource | Ceph Resources to be cleaned up |
| -------- | ------- |
| CephFilesystemSubVolumeGroup | CSI stored RADOS OMAP details for pvc/volumesnapshots, subvolume snapshots, subvolume clones, subvolumes |
| CephBlockPoolRadosNamespace | Images and snapshots in the RADOS namespace|