MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

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

PropRaahi: How a New Property Research Platform Is Tackling India’s Biggest Real Estate Problems

From confusing property documents and hidden costs to unreliable information and buyer uncertainty, PropRaahi wants to make property buying in India more transparent, informed, and buyer-friendly. India’s…

Read More

Why Engineers Click Through Compliance Training – and What DevOps Teams Can Do About It

Ask a room of engineers about their annual compliance module and you will hear the same story: a slide deck on data protection, a few multiple-choice questions,…

Read More

Could An AI Chatbot Help Your Business Deliver Better Customer Support? What To Know About Implementing One

Customers don’t always have the time or patience to wait for answers. From checking delivery times and asking about a service to trying to resolve a problem,…

Read More

How to stop support escalations eating your engineering time

Nobody decides that engineers should do support. It happens one message at a time. A ticket looks odd, L1 isn’t sure, and someone pings the developer who…

Read More

Best Print Driver Management Software for IT Teams in 2027: 7 Tools Compared

Microsoft’s end-of-servicing plan for legacy third-party printer drivers is reshaping how IT teams handle print management. From January 15, 2026, no new printer drivers are published to…

Read More

Switching EOR Providers: How to Protect Your Employees and Keep Work on Track

Changing an employment provider can affect payroll, employee records, benefits and day-to-day support. Without careful planning, even a necessary transition can create uncertainty for international employees. A…

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
11 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
11 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