Delete Percona Operator for PostgreSQL¶
When cleaning up your Kubernetes environment (e.g., moving from a trial deployment to a production one, or testing experimental configurations), you may need to remove some (or all) of the following objects:
- Percona Distribution for PosgreSQL cluster managed by the Operator
- Percona Operator for PostgreSQL itself
- Custom Resource Definition deployed with the Operator
- Resources like PVCs and Secrets
Delete a database cluster¶
You can delete the Percona Distribution for PosgreSQL cluster managed by the Operator by deleting the appropriate Custom Resource.
Note
There are two finalizers defined in the Custom Resource, which define whether TLS-related objects and data volumes should be deleted or preserved when the cluster is deleted.
finalizers.percona.com/delete-ssl: if present, deletes objects, created for SSL (Secret, certificate, and issuer) when the cluster deletion occurs.finalizers.percona.com/delete-pvc: if present, deletes Persistent Volume Claims for the database cluster Pods and user Secrets when the cluster deletion occurs.
Both finalizers are off by default in the deploy/cr.yaml configuration file, and this allows you to recreate the cluster without losing data, credentials for the system users, etc.
Removing a logical replica from spec.logicalReplicas always deletes its PVC (<cluster>-lr-<name>-pgdata), even if finalizers.percona.com/delete-pvc is not set. If the primary is down during removal, the replica stays in status with reason AwaitingCleanup until slots can be dropped. See Remove a logical replica.
Here’s a sequence of steps to follow:
-
List Custom Resources, replacing the
<namespace>placeholder with your namespace.kubectl get pg -n <namespace>Sample output
NAME ENDPOINT STATUS POSTGRES PGBOUNCER AGE cluster1 cluster1-pgbouncer.default.svc ready 3 3 30m -
Delete the Custom Resource with the name of your cluster (for example, let’s use the default
cluster1name).kubectl delete pg cluster1 -n <namespace>Sample output
perconapgcluster.pgv2.percona.com "cluster1" deleted -
Check that the cluster is deleted by listing the available Custom Resources once again.
kubectl get pg -n <namespace>Sample output
No resources found in <namespace> namespace.
Delete the Operator¶
You can uninstall the Operator by deleting the Deployments related to it.
-
List the deployments. Replace the
<namespace>placeholder with your namespace.kubectl get deploy -n <namespace>Sample output
NAME READY UP-TO-DATE AVAILABLE AGE percona-postgresql-operator 1/1 1 1 13m -
Delete the
percona-*deploymentkubectl delete deploy percona-postgresql-operator -n <namespace> -
Check that the Operator is deleted by listing the Pods. As a result you should have no Pods related to it.
kubectl get pods -n <namespace>Sample output
No resources found in <namespace> namespace.
Delete Custom Resource Definition¶
If you are not just deleting the Operator and PostgreSQL cluster from a specific namespace, but want to clean up your entire Kubernetes environment, you can also delete the CustomResourceDefinitions (CRDs) .
Warning
CRDs in Kubernetes are non-namespaced but are available to the whole environment. This means that you shouldn’t delete CRD if you still have the Operator and database cluster in some namespace.
You can delete CRD as follows:
-
List the CRDs:
kubectl get crdSample output
allowlistedv2workloads.auto.gke.io 2023-09-07T14:15:30Z allowlistedworkloads.auto.gke.io 2023-09-07T14:15:29Z audits.warden.gke.io 2023-09-07T14:15:32Z backendconfigs.cloud.google.com 2023-09-07T14:15:41Z capacityrequests.internal.autoscaling.gke.io 2023-09-07T14:15:25Z frontendconfigs.networking.gke.io 2023-09-07T14:15:41Z managedcertificates.networking.gke.io 2023-09-07T14:15:41Z memberships.hub.gke.io 2023-09-07T14:15:30Z perconapgbackups.pgv2.percona.com 2023-09-07T14:28:59Z perconapgclusters.pgv2.percona.com 2023-09-07T14:29:02Z perconapgrestores.pgv2.percona.com 2023-09-07T14:29:03Z postgresclusters.postgres-operator.crunchydata.com 2023-09-07T14:29:06Z serviceattachments.networking.gke.io 2023-09-07T14:15:44Z servicenetworkendpointgroups.networking.gke.io 2023-09-07T14:15:43Z storagestates.migration.k8s.io 2023-09-07T14:15:53Z storageversionmigrations.migration.k8s.io 2023-09-07T14:15:53Z updateinfos.nodemanagement.gke.io 2023-09-07T14:15:55Z volumesnapshotclasses.snapshot.storage.k8s.io 2023-09-07T14:15:52Z volumesnapshotcontents.snapshot.storage.k8s.io 2023-09-07T14:15:52Z volumesnapshots.snapshot.storage.k8s.io 2023-09-07T14:15:52Z -
Now delete the
percona*.pgv2.percona.comCRDs:kubectl delete crd perconapgbackups.pgv2.percona.com perconapgclusters.pgv2.percona.com perconapgrestores.pgv2.percona.comSample output
customresourcedefinition.apiextensions.k8s.io "perconapgbackups.pgv2.percona.com" deleted customresourcedefinition.apiextensions.k8s.io "perconapgclusters.pgv2.percona.com" deleted customresourcedefinition.apiextensions.k8s.io "perconapgrestores.pgv2.percona.com" deleted
Clean up resources¶
By default, TLS-related objects and data volumes remain in Kubernetes environment after you delete the cluster to allow you to recreate it without losing the data.
You can automate resource cleanup by turning on percona.com/delete-pvc and/or percona.com/delete-ssl finalizers). You can also delete TLS-related objects and PVCs manually.
To manually clean up resources, do the following:
-
Delete Persistent Volume Claims.
-
List PVCs. Replace the
<namespace>placeholder with your namespace:kubectl get pvc -n <namespace>Sample output
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE cluster1-instance1-mkwh-pgdata Bound pvc-c22220e9-c5e9-40b8-91b5-3d437b40bdec 1Gi RWO standard-rwo <unset> 4m17s cluster1-instance1-nvh4-pgdata Bound pvc-61a64aca-5165-4d25-b055-efc455d545b8 1Gi RWO standard-rwo <unset> 4m17s cluster1-instance1-qknb-pgdata Bound pvc-87bc6549-ee49-47f5-9f5e-83a315f78fd9 1Gi RWO standard-rwo <unset> 4m18s cluster1-repo1 Bound pvc-380e1100-b679-4716-ae8f-78372448b5f0 1Gi RWO standard-rwo <unset> 4m15s -
Delete PVCs related to your cluster. The following command deletes PVCs for the
cluster1cluster:kubectl delete pvc cluster1-instance1-mkwh-pgdata cluster1-instance1-nvh4-pgdata cluster1-instance1-qknb-pgdata cluster1-repo1 -n <namespace>Sample output
persistentvolumeclaim "cluster1-instance1-mkwh-pgdata" deleted persistentvolumeclaim "cluster1-instance1-nvh4-pgdata" deleted persistentvolumeclaim "cluster1-instance1-qknb-pgdata" deleted persistentvolumeclaim "cluster1-repo1" deletedNote that if your Custom Resource manifest includes the
percona.com/delete-pvcfinalizer, all user Secrets will be automatically deleted when you delete the PVCs. To prevent this from happening, disable the finalizer.Logical replica volumes are named
<cluster>-lr-<name>-pgdata. The Operator deletes them when you remove the replica from the spec. Delete any leftover claims here if teardown could not finish (for example, the primary was down). -
Delete the Secrets
-
List Secrets:
kubectl get secrets -n <namespace> -
Delete the Secret:
kubectl delete secret <secret_name> -n <namespace>
-
-
Created: September 14, 2023