When things go wrong, we need to take hard decisions like deleting the finalizers on Kubernetes objects.
Cleaning the finalizers is easy, but the consequence can be dramatic. This page supposes that you know what you are doing.
We take the approach of patching Kubernetes objects, manually and programmatically (which is the same but no need to know exactly the kubectl command).
Way #1: Manual approach
List the objects your want to detach from any external attraction.
kubectl get database.postgresql.sql.crossplane.io
database.postgresql.sql.crossplane.io/postgresql-b7t9d-4ff7g
Patch the targeted resource to delete any entry in the finalizer attribute.
kubectl patch database.postgresql.sql.crossplane.io/postgresql-b7t9d-4ff7g -p '{"metadata":{"finalizers":null}}'
database.postgresql.sql.crossplane.io/postgresql-b7t9d-4ff7g patched
Way #2: Script approach
Create a simple script in /usr/local/bin
that wrap the patch finalizer.
touch /usr/local/bin/kfinalizer chmod +x /usr/local/bin/kfinalizer /usr/local/bin/kfinalizer
#!/bin/bash
kubectl patch -p '{"metadata":{"finalizers":null}}' --type=merge $@
Run the script on the targeted object.
kfinalizer database.postgresql.sql.crossplane.io/postgresql-b7t9d-4ff7g
database.postgresql.sql.crossplane.io/postgresql-b7t9d-4ff7g patched
Bibliography
- Kubernetes finalizers concept: https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/
- Kubernetes Operator pattern: https://kubernetes.io/docs/concepts/extend-kubernetes/operator/