Skip to content

Delete Percona Operator for MongoDB

You may have different reasons to clean up your Kubernetes environment: moving from trial deployment to a production one, testing experimental configurations and the like. In either case, you need to remove some (or all) of these objects:

  • Percona Distribution for MongoDB cluster managed by the Operator
  • Percona Operator for MongoDB itself
  • Custom Resource Definition deployed with the Operator
  • Resources like PVCs and Secrets

Delete the database cluster

To delete the database cluster means to delete the Custom Resource associated with it.

Note

There are two finalizers defined in the Custom Resource, which define whether to delete or preserve TLS-related objects and data volumes when the cluster is deleted.

  • finalizers.percona.com/delete-ssl: if present, objects, created for SSL (Secret, certificate, and issuer) are deleted along with the cluster deletion.
  • finalizers.percona.com/delete-pvc: if present, Persistent Volume Claims for the database cluster Pods are deleted along with the cluster deletion.

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. You can always delete TLS-related objects and PVCs manually, if needed.

The steps are the following:

  1. List the Custom Resources. Replace the <namespace> placeholder with your value

    $ kubectl get psmdb -n <namespace>
    
  2. Delete the Custom Resource with the name of your cluster

    $ kubectl delete psmdb <cluster_name> -n <namespace>
    

    It may take a while to stop and delete the cluster.

    Sample output
    perconaservermongodb.psmdb.percona.com "my-cluster-name" deleted
    
  3. Check that the cluster is deleted by listing the Custom Resources again:

    $ kubectl get psmdb -n <namespace>
    
    Sample output
    No resources found in <namespace> namespace.
    

Delete the Operator

Choose the instructions relevant to the way you installed the Operator.

To uninstall the Operator, delete the Deployments related to it.

  1. List the deployments. Replace the <namespace> placeholder with your namespace.

    $ kubectl get deploy -n <namespace>
    
  2. Delete the percona-* deployment

    $ kubectl delete deploy percona-server-mongodb-operator -n <namespace>
    
  3. 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.
    
  4. If you are not just deleting the Operator and MongoDB cluster from a specific namespace, but want to clean up your entire Kubernetes environment, you can also delete the CustomRecourceDefinitions (CRDs) .

    Warning: CRDs in Kubernetes are non-namespaced but are available to the whole environment. This means that you shouldn’t delete CRDs if you still have the Operator and database cluster in some namespace.

    Get the list of CRDs.

    $ kubectl get crd
    
  5. Delete the percona*.psmdb.percona.com CRDs

    $ kubectl delete crd perconaservermongodbbackups.psmdb.percona.com perconaservermongodbrestores.psmdb.percona.com perconaservermongodbs.psmdb.percona.com
    
    Sample output
    customresourcedefinition.apiextensions.k8s.io "perconaservermongodbbackups.psmdb.percona.com" deleted
    customresourcedefinition.apiextensions.k8s.io "perconaservermongodbrestores.psmdb.percona.com" deleted
    customresourcedefinition.apiextensions.k8s.io "perconaservermongodbs.psmdb.percona.com" deleted
    

To delete the Operator, do the following:

  1. List the Helm charts:

    $ helm list -n <namespace>
    
    Sample output
    cluster1    <namespace>         1           2023-10-31 10:18:10.763049 +0100 CET    deployed    psmdb-db-1.14.4         1.15.0
    my-op       <namespace>         1           2023-10-31 10:15:18.41444 +0100 CET     deployed    psmdb-operator-1.14.3   1.15.0
    
  2. Delete the release object for Percona Server for MongoDB

    $ helm uninstall cluster1 --namespace <namespace>
    
  3. Delete the release object for the Operator

    $ helm uninstall my-op --namespace <namespace>
    

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. If you wish to delete them, do the following:

  1. Delete Persistent Volume Claims.

    1. List PVCs. Replace the <namespace> placeholder with your namespace:

      $ kubectl get pvc -n <namespace>
      
      Sample output
      NAME                                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
      mongod-data-my-cluster-name-cfg-0   Bound    pvc-245641fe-b172-439b-8c9c-cba5ea4ccd80   3Gi        RWO            standard-rwo   10m
      mongod-data-my-cluster-name-cfg-1   Bound    pvc-4ff7c3c4-b91c-4938-a52e-591fd559f4a4   3Gi        RWO            standard-rwo   9m19s
      mongod-data-my-cluster-name-cfg-2   Bound    pvc-acbff4a3-784a-48e7-ad4b-8b00239982d3   3Gi        RWO            standard-rwo   8m36s
      mongod-data-my-cluster-name-rs0-0   Bound    pvc-0a56e9ab-e22b-47ce-95de-a55f2676456a   3Gi        RWO            standard-rwo   10m
      mongod-data-my-cluster-name-rs0-1   Bound    pvc-cd075679-a7f5-4182-a8ce-341db1fb12d3   3Gi        RWO            standard-rwo   9m19s
      mongod-data-my-cluster-name-rs0-2   Bound    pvc-9ff0d41d-c739-494d-a45c-576f3a1fb590   3Gi        RWO            standard-rwo   8m26s
      
    2. Delete PVCs related to your cluster. The following command deletes PVCs for the my-cluster-name cluster:

      $ kubectl delete pvc mongod-data-my-cluster-name-cfg-0 mongod-data-my-cluster-name-cfg-1 mongod-data-my-cluster-name-cfg-2 mongod-data-my-cluster-name-rs0-0 mongod-data-my-cluster-name-rs0-1 mongod-data-my-cluster-name-rs0-2 -n <namespace>
      
      Sample output
      persistentvolumeclaim "mongod-data-my-cluster-name-cfg-0" deleted persistentvolumeclaim "mongod-data-my-cluster-name-cfg-1" deleted
      persistentvolumeclaim "mongod-data-my-cluster-name-cfg-2" deleted
      persistentvolumeclaim "mongod-data-my-cluster-name-rs0-0" deleted
      persistentvolumeclaim "mongod-data-my-cluster-name-rs0-1" deleted
      persistentvolumeclaim "mongod-data-my-cluster-name-rs0-2" deleted
      
  2. Delete the Secrets

    1. List Secrets:

      $ kubectl get secrets -n <namespace>
      
    2. Delete the Secret:

      $ kubectl delete secret <secret_name> -n <namespace>
      

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services. Join K8S Squad to benefit from early access to features and “ask me anything” sessions with the Experts.


Last update: 2024-04-26