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 a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Top 10 AI Code Generation for Scientific Computing Tools: Features, Pros, Cons & Comparison

Introduction AI Code Generation Tools for Scientific Computing combine artificial intelligence, machine learning, and programming assistance to help researchers, engineers, and scientists write, optimize, and maintain scientific…

Read More

Top 10 AI Computer-Aided Engineering Assistants: Features, Pros, Cons & Comparison

Introduction AI Computer-Aided Engineering (CAE) Assistants combine artificial intelligence, machine learning, automation, and engineering knowledge to help engineers improve design, simulation, analysis, and optimization workflows. These assistants…

Read More

Top 10 AI Materials Informatics Platforms: Features, Pros, Cons & Comparison

Introduction AI Materials Informatics Platforms combine artificial intelligence, machine learning, data analytics, and materials science to accelerate the discovery, development, and optimization of new materials. These platforms…

Read More

Top 10 AI CFD Acceleration Toolkits: Features, Pros, Cons & Comparison

Introduction AI CFD Acceleration Toolkits use artificial intelligence, machine learning, and scientific computing techniques to speed up Computational Fluid Dynamics (CFD) simulations. Traditional CFD simulations can require…

Read More

Top 10 Physics-Informed Neural Network (PINN) Frameworks: Features, Pros, Cons & Comparison

Introduction Physics-Informed Neural Network (PINN) Frameworks are AI and machine learning platforms designed to combine neural networks with mathematical equations, physical laws, and scientific constraints. Unlike traditional…

Read More

Top 10 AI Surrogate Modeling Tools: Features, Pros, Cons & Comparison

Introduction AI Surrogate Modeling Tools use artificial intelligence, machine learning, and statistical modeling techniques to create fast approximations of complex simulations, experiments, and computational processes. Instead of…

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