Sobes.tech
Senior

Why can a namespace remain in the Terminating status for more than a day?

sobes.tech AI

Answer from AI

A Namespace in Kubernetes can remain in the Terminating status for a long time because some resources inside it were not properly deleted or got stuck.

Main reasons:

  • Stuck finalizers — special handlers that should perform cleanup before deleting a resource. If a finalizer does not complete (for example, due to an error in the controller), the namespace will not be deleted.
  • Remaining resources — if there are objects inside the namespace that are not being deleted (for example, Pods with issues), the namespace will not finish deletion.
  • Problems with the API server or controllers — if cluster components are not functioning correctly, the deletion process may hang.

For diagnostics, you can:

  • Check for finalizers on the namespace and resources inside:
kubectl get namespace <name> -o json | jq '.spec.finalizers'
  • Manually delete problematic finalizers if they are stuck:
kubectl patch namespace <name> -p '{"metadata":{"finalizers":null}}' --type=merge
  • Check the status of resources inside the namespace and delete them manually.

Thus, the prolonged Terminating status is usually related to stuck cleanup processes and requires manual intervention to complete the deletion.