Kubernetes: What are finalizers?
1. What are finalizers, really?
When you delete a Kubernetes object (CRD, Namespace, Pod, etc.), Kubernetes does not delete it immediately.
Instead it:
- Sets
metadata.deletionTimestamp - Leaves the object in place
- Waits for all finalizers to be removed from
metadata.finalizers
A finalizer is just a string tag like:
"kubernetes"(for namespaces)"customresourcecleanup.apiextensions.k8s.io"(for CRDs)"finalizer.keda.sh"(for KEDA)"foregroundDeletion"(for some resources)
It means:
โBefore you remove this object from etcd, call the controller that owns this finalizer so it can clean stuff up (external state, dependent resources, DNS, volumes, etc). Once itโs done, it will remove its finalizer, and then K8s can truly delete the object.โ
So if the responsible controller never does its job, or is gone, or is misconfigured โ finalizer never gets removed โ resource stays Terminating forever.
Thatโs exactly what you saw with:
customresourcecleanup.apiextensions.k8s.ioon your CRDskubernetesfinalizer on thekedanamespace
2. Why does it sometimes take SO long (or never complete)?
Common reasons:
- Controller is gone or broken
- You deleted the operator/Helm release before deleting the CRD or its instances
- Now the CRD has finalizers, but the controller that should remove them no longer exists
- Kubernetes waitsโฆ forever.
- Controller canโt reach its backend
- For example, deletion wants to clean something in AWS, but AWS creds are broken
- Cleanup fails, finalizer stays, resource never finishes deleting.
- Namespace-level finalizer (
kubernetes)- When you delete a namespace, K8s tries to clean everything inside it
- If any object is stuck (webhook, CRD instance, PVC, etc.), the namespace stays
Terminatingforever.
- Buggy or over-eager operators
- Some operators add finalizers everywhere but donโt handle edge cases well.
So the long waits / hangs are by design: Kubernetes is saying
โBefore I forget this object, I must give controllers a chance to clean up external stuff.โ
3. Is there a โbetterโ way? (In practice)
Thereโs no magic global flag like โignore all finalizersโ, but you can make this much less painful by following some practices:
a) Always uninstall the app/operator correctly
For things like KEDA, Prometheus, cert-manager, etc:
- Prefer Helm uninstall or vendorโs documented uninstall procedure.
- This gives the operator time to:
- Clean its CR instances
- Remove finalizers from them
- Let CRDs/namespace delete without hanging
Deleting CRDs or namespaces first and operators later is the most common way to get into trouble.
b) Only patch finalizers as a last resort
What you did (patching finalizers: []) is the right last step, but it comes with trade-offs:
- Youโre telling K8s: โDonโt wait for cleanup, just forget this resource.โ
- If the controller was supposed to delete something external (buckets, DNS, etc.), that cleanup may never happen.
For dev/sandbox clusters โ totally fine.
For prod โ should be done carefully, knowing what might be left behind.
c) How to quickly diagnose โwhy is this stuck?โ
When something is Terminating forever, my standard steps are:
- Check finalizers:
kubectl get <kind> <name> -n <ns> -o jsonpath='{.metadata.finalizers}'That tells you who is holding the deletion. - Check events:
kubectl describe <kind> <name> -n <ns>Sometimes youโll see helpful errors like:- โcannot contact webhook โฆโ
- โfailed to clean up custom resources โฆโ
- Check controller logs for the finalizer owner
- For KEDA finalizer โ
kubectl logs -n keda deploy/keda-operator - For CRD cleanup โ
kube-apiserver/apiextensions-apiserverlogs (harder on managed clusters)
- For KEDA finalizer โ
d) How to avoid this pain in future?
For your use case (EKS + addons like KEDA, Datadog, etc.):
- Use Helm (or GitOps) as the source of truth
- Install/upgrade/uninstall via Helm.
- When decommissioning:
helm uninstall <release>first, then delete CRDs if needed.
- Donโt nuke CRDs and namespaces first
- If you need to remove KEDA:
helm uninstall keda -n keda- Wait for CRs to disappear.
- Then remove CRDs if you really want.
- If you need to remove KEDA:
- Keep operators running until cleanup is finished
- Donโt delete operator deployments before their resources are gone.
- Accept that in dev, patching is normal
- In dev/sandbox clusters, patching finalizers (
kubectl patch ... finalizers: []) is a perfectly OK escape hatch.
- In dev/sandbox clusters, patching finalizers (
4. TL;DR in human language
- Finalizers are โhooksโ that block deletion until cleanup is done.
- Theyโre good for correctness, but awful for UX if the responsible controller is gone or broken.
- Thatโs why your CRDs and namespace took ages / got stuck.
- Best you can do:
- Uninstall apps the clean way (Helm uninstall, not CRD delete first).
- Only patch-out finalizers when you know what youโre skipping.
- In dev: patching is fine. In prod: be deliberate.
Iโm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
This article provides a great insight into the concept of finalizers in Kubernetes. It effectively explains how finalizers serve as a mechanism to ensure that resources are cleaned up properly before they are deleted. The explanation of how Kubernetes uses finalizers to perform necessary cleanup operations, such as removing related resources or performing other actions, is particularly helpful for developers managing Kubernetes clusters. Itโs also valuable to understand how finalizers prevent objects from being prematurely deleted, ensuring that all dependencies are handled correctly. This makes managing resources in Kubernetes much more reliable and efficient.
This article does a great job of breaking down what โfinalizersโ are in Kubernetes and why they matter for safe resource cleanup. By explaining that finalizers act as โpreโdelete hooks,โ it clarifies how Kubernetes delays the permanent deletion of an object until cleanup tasks (like removing associated external resources or dependencies) are completed โ avoiding orphaned resources or data leaks. The postโs overview of common builtโin finalizers (e.g. for persistent volumes / claims), and how custom controllers/operators can use finalizers for cleanup logic, makes the concept very approachable. For anyone managing Kubernetes clusters or building custom controllers, this is a mustโread to correctly implement resource lifecycle and avoid deletionโrelated surprises.