Clean up PDS resources post-cluster deletion
When you delete a cluster in the PDS platform, it is essential to clean up all associated resources to avoid any residual data or configurations that might interfere with future deployments. Below is a detailed explanation of the steps to clean up these resources effectively.
Prerequisites
- PDS Account admin privileges
- A deleted target cluster
Procedure
-
Identify all namespaces with PDS installations using the following commands:
nsl1=`kubectl get namespace -lplatform.portworx.io/pds=true -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'`
nsl2=`kubectl get namespace -lplatform.portworx.com/pds=true -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'`
echo $nsl1"\n"$nsl2 | sort -uThis will list all namespaces labeled with
platform.portworx.io/pds=true
orplatform.portworx.com/pds=true
, ensuring you have a comprehensive list of namespaces with PDS installations. -
For each namespace, you need to identify and clean up all data services. Follow these steps:
2.1. Get the type of data services installed in each namespace:
kubectl get database -n <namespace> -ojson -o=jsonpath='{range .items[*]}{.spec.application}{"\n"}{end}' | sort -u
2.2. Delete each data service type. For example, if the namespace is
pds-ns
and you need to delete a PostgreSQL data service:kubectl get postgresql.deployments.pds.portworx.com -n pds-ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{} kubectl -n pds-ns patch postgresql.deployments.pds.portworx.com {} -p '{"metadata":{"finalizers":null}}' --type=merge
The above command will remove the finalizers.
kubectl get database -n pds-ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{} kubectl -n pds-ns patch database {} -p '{"metadata":{"finalizers":null}}' --type=merge
kubectl get postgresql.deployments.pds.portworx.com -n pds-ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{} kubectl -n pds-ns delete postgresql.deployments.pds.portworx.com {}
The above commands will remove the data service.
-
If the data is not required, clean up the volumes and storage classes:
kubectl delete pvc -n <namespace> -l pds/deployment-id
kubectl delete storageclass -l pds/deployment-id
kubectl delete persistentvolume -l pds/deployment-id
-
Ensure that all backup configurations and targets are deleted:
4.1. Remove finalizers and delete backup configurations:
kubectl get backupconfig.backups.pds.portworx.com -n pds-ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{} kubectl patch backupconfig.backups.pds.portworx.com -n pds-ns {} -p '{"metadata":{"finalizers":null}}' --type=merge
kubectl get backupconfig.backups.pds.portworx.com -n pds-ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{} kubectl delete backupconfig.backups.pds.portworx.com -n pds-ns {}
4.2. Remove finalizers and delete backups:
kubectl get backup.backups.pds.portworx.com -n pds-ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{}
kubectl patch backup.backups.pds.portworx.com -n pds-ns {} -p '{"metadata":{"finalizers":null}}' --type=merge
4.3. Remove finalizers and delete backup targets:
kubectl get backuptargets.backups.pds.portworx.com -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | xargs -I{}
kubectl patch backuptargets.backups.pds.portworx.com {} -p '{"metadata":{"finalizers":null}}' --type=merge
kubectl get backuptargets.backups.pds.portworx.com | xargs -I{} kubectl delete backuptargets.backups.pds.portworx.com {}
4.4. Delete volume snapshots if data has to be deleted in cloud buckets:
kubectl delete volumesnapshots.volumesnapshot.external-storage.k8s.io -n pds-ns -l pds/deployment-id
-
Clean up any CRDs related to PDS:
kubectl get crd | sed 's/ .*//' | grep pds | while read -r line; do kubectl delete crd $line; done