Managed Kubernetes
Latest
Frequently Asked Questions
Solutions
How Tos
Internal Only
Templates
Powered By

Title
Message
Create new category
What is the title of your new category?
Edit page index title
What is the title of the page index?
Edit category
What is the new title of your category?
Edit link
What is the new title and URL of your link?
Why Namespace Deletion is Stuck Due to Finalizers
Copy Markdown
Open in ChatGPT
Open in Claude
Problem
Kubernetes namespace is stuck in terminating state due to finalizers.
Javascript
xxxxxxxxxx# kubectl get ns test-nsNAME STATUS AGEtest-ns Terminating 15mEnvironment
- Platform9 Managed Kubernetes - All Versions
Answer
- Sometimes the process to delete namespaces gets stuck, and the command never completes. While the command returns a message showing that the namespace was deleted, querying it indicates that it's actually in a
Terminatingstate. - On some occasions, namespaces have a finalizer defined under
spec. A finalizer is a special metadata key that tells Kubernetes to wait until a specific condition is met before it fully deletes a resource. - So when one runs a command like
kubectl delete namespace abcd, Kubernetes checks for a finalizer in themetadata.finalizersfield. If the resource defined in the finalizer cannot be deleted for any reason, then the namespace is not deleted either. This puts the namespace into a terminating state awaiting the removal of the resource, which never occurs.
Bash
xxxxxxxxxx$ kubectl delete namespace test-nsnamespace "test-ns" deleted $ kubectl get namespaceNAME STATUS AGEtest-ns Terminating 15m- The correct way to avoid this issue is to make sure that all the resources in the namespace are deleted before you delete a namespace. As a workaround, removing the finalizers will allow the stuck namespace to be deleted.
- The finalizers can be removed for the affected namespace using the steps mentioned below.
Steps to remove Finalizers From Stuck Namespace
xxxxxxxxxx# kubectl get namespace <stuck_namespace> -o json > <stuck_namespace>.json# kubectl replace --raw "/api/v1/namespaces/<stuck_namespace>/finalize" -f ./<stuck_namespace>.json# kubectl get namespaceVariableType to search · ESC to discard
GlossaryType to search · ESC to discard
InsertType to search · ESC to discard
No matches
Last updated on
Was this page helpful?
Discard Changes
Do you want to discard your current changes and overwrite with the template?
Archive Synced Block
Message
Create new Template
What is this template's title?
Delete Template
Message