Home › Kubernetes

Namespace stuck in Terminating (Kubernetes) — how to fix

$ kubectl get namespace my-ns
NAME    STATUS        AGE
my-ns   Terminating   3d

Error from server (Conflict): Operation cannot be fulfilled on namespaces "my-ns": The system is ensuring all content is removed from this namespace.  Upon completion, this namespace will automatically be purged by the system.

Quick fix: Run kubectl get ns my-ns -o jsonpath='{.status.conditions}' to see what's blocking. If an APIService is unavailable (kubectl get apiservice | grep False), fix or delete it. If resources with finalizers remain, list them and remove the finalizer with kubectl patch <kind> <name> -n my-ns --type=merge -p '{"metadata":{"finalizers":null}}'.

What it means

Deleting a namespace starts a cleanup: Kubernetes deletes every object in it, waits for their finalizers, and only then removes the namespace. If any object can't be deleted, or the namespace controller can't even list some resource type, the namespace stays in Terminating forever.

Start by asking the namespace itself what's wrong:

kubectl get namespace my-ns -o jsonpath='{range .status.conditions[*]}{.type}{": "}{.message}{"\n"}{end}'

The conditions name the cause, for example NamespaceDeletionDiscoveryFailure or NamespaceContentRemaining / NamespaceFinalizersRemaining.

Cause 1: an API service is unavailable

If an aggregated API (often metrics-server, or an operator's API whose pods are gone) is down, the controller can't list its resources and won't finish.

kubectl get apiservice | grep False

Fix: bring the service back (redeploy metrics-server or the operator), or, if it's left over from something you uninstalled, delete it:

kubectl delete apiservice v1beta1.metrics.k8s.io   # use the name from the list

The namespace usually disappears within a minute.

Cause 2: resources with finalizers remain

Custom resources often have finalizers that their controller removes once it has cleaned up. If you uninstalled the controller first, nobody removes the finalizer.

List everything still in the namespace:

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -n my-ns

Fix (best): reinstall the controller or operator briefly so it can finish its cleanup, then uninstall it after the namespace is gone.

Fix (if the controller is gone for good): remove the finalizer from each stuck object:

kubectl get <kind> <name> -n my-ns -o jsonpath='{.metadata.finalizers}'
kubectl patch <kind> <name> -n my-ns --type=merge -p '{"metadata":{"finalizers":null}}'

Removing a finalizer skips whatever cleanup it guarded, for example deleting an external load balancer, cloud disk or DNS record. Check for orphaned cloud resources afterwards.

PersistentVolumeClaims carrying kubernetes.io/pvc-protection stay until pods using them are gone. Delete those pods first instead of patching the PVC.

Cause 3: last resort, finalize the namespace directly

If the namespace is empty, or you accept leaving things behind in etcd, clear the namespace's own kubernetes finalizer through the finalize subresource (needs jq):

kubectl get namespace my-ns -o json \
  | jq '.spec.finalizers = []' \
  | kubectl replace --raw "/api/v1/namespaces/my-ns/finalize" -f -

Objects that were still inside can linger in etcd and reappear if you recreate a namespace with the same name, so use Causes 1 and 2 first.

Prevent it

Delete in the reverse order of installation: first the custom resources (and wait until they're gone), then the operator/controller, then its CRDs and namespace. With Helm, uninstall the release before deleting its namespace.

Last updated 2026-12-04.