Delete a MongoDB cluster
Termination policy
note
The termination policy determines how a cluster is deleted. Set the policy when creating a cluster.
terminationPolicy | Deleting Operation |
---|---|
DoNotTerminate | DoNotTerminate blocks delete operation. |
Halt | Halt deletes Cluster resources like Pods and Services but retains Persistent Volume Claims (PVCs), allowing for data preservation while stopping other operations. Halt policy is deprecated in v0.9.1 and will have same meaning as DoNotTerminate. |
Delete | Delete extends the Halt policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data. |
WipeOut | WipeOut deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, especially in non-production environments, to avoid irreversible data loss. |
To check the termination policy, execute the following command.
- kbcli
- kubectl
kbcli cluster list mycluster -n demo
kubectl get cluster mycluster -n demo
>
NAME CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS AGE
mycluster mongodb mongodb-5.0 Delete Running 17m
Steps
Run the command below to delete a specified cluster.
- kbcli
- kubectl
kbcli cluster delete mycluster -n demo
kubectl delete -n demo cluster mycluster
If you want to delete a cluster and its all related resources, you can set the termination policy to WipeOut
, and then delete the cluster.
kubectl patch -n demo cluster mycluster -p '{"spec":{"terminationPolicy":"WipeOut"}}' --type="merge"
kubectl delete -n demo cluster mycluster