Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

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:

  1. Sets metadata.deletionTimestamp
  2. Leaves the object in place
  3. 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.io on your CRDs
  • kubernetes finalizer on the keda namespace

2. Why does it sometimes take SO long (or never complete)?

Common reasons:

  1. 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.
  2. 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.
  3. 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 Terminating forever.
  4. 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:

  1. Check finalizers: kubectl get <kind> <name> -n <ns> -o jsonpath='{.metadata.finalizers}' That tells you who is holding the deletion.
  2. Check events:kubectl describe <kind> <name> -n <ns> Sometimes youโ€™ll see helpful errors like:
    • โ€œcannot contact webhook โ€ฆโ€
    • โ€œfailed to clean up custom resources โ€ฆโ€
  3. Check controller logs for the finalizer owner
    • For KEDA finalizer โ†’ kubectl logs -n keda deploy/keda-operator
    • For CRD cleanup โ†’ kube-apiserver / apiextensions-apiserver logs (harder on managed clusters)

d) How to avoid this pain in future?

For your use case (EKS + addons like KEDA, Datadog, etc.):

  1. 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.
  2. 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.
  3. Keep operators running until cleanup is finished
    • Donโ€™t delete operator deployments before their resources are gone.
  4. Accept that in dev, patching is normal
    • In dev/sandbox clusters, patching finalizers (kubectl patch ... finalizers: []) is a perfectly OK escape hatch.

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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

The Role of Automation in Modern iGaming Infrastructure

The iGaming industry operates in a fast-moving digital environment where scalability, reliability, security and speed are essential. Online sportsbooks and casino platforms need to handle high traffic,…

Read More

Running LLM Workloads Like Any Other Production Service: A DevOps Playbook for Model APIs

A model API is a dependency like any other, and it deserves the same operational discipline. Photo via Unsplash. When a team ships its first feature built…

Read More

Combining Tech Skills with Higher Education: Strategies for Top University Admissions

The modern higher education landscape has shifted dramatically, moving away from purely standardized metrics toward holistic evaluations where applied, real-world skills matter deeply. Secondary school students who…

Read More

What a Financial Strategy Partner Brings Beyond Basic Advisory

Basic advisory explains what happened in a business. A financial strategy partner helps leaders decide what should happen next. That difference matters when growth creates cash pressure,…

Read More

Designing a production-ready web scraping pipeline that survives blocks, retries, and CI

Most scraping failures in production look like random network noise. The real cause is usually a weak contract between your code and the target site. You deploy…

Read More

Top 7 Bare-Metal AI Infrastructure Providers

Bare-metal AI infrastructure providers give teams dedicated physical compute, but the buying experience varies considerably: some supply individual GPU servers that your engineers operate, while others take…

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
10 months ago

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.

Skylar Bennett
Skylar Bennett
10 months ago

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.

2
0
Would love your thoughts, please comment.x
()
x