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
Uninstall PDS Helm charts and clean up resources
Follow these steps to uninstall PDS Helm charts, remove associated resources, and clean up your cluster:
-
If you are using PDS version 24.12.01 or later, start by uninstalling the
pds-external-dns
Helm chart:helm uninstall pds-external-dns -n px-system
-
Uninstall the main
pds
Helm chart:helm uninstall pds -n px-system
-
Uninstall the
px-agent
Helm chart:helm uninstall px-agent -n px-system
-
Remove the
px-system
namespace that was created during cluster registration:kubectl delete ns px-system
-
Identify and delete all CRDs related to PDS:
kubectl get crd | sed 's/ .*//' | grep pds | while read -r line; do kubectl delete crd $line; done
-
Identify and delete all CRDs related to Portworx Agent:
kubectl get crd | sed 's/ .*//' | grep targetcluster | while read -r line; do kubectl delete crd $line; done
-
Delete the ClusterRoles created by the Portworx bootstrapper:
kubectl delete clusterroles -l app.kubernetes.io/instance=px-bootstrapper
-
Delete the ClusterRoleBindings created by the Portworx bootstrapper:
kubectl delete clusterrolebindings -l app.kubernetes.io/instance=px-bootstrapper