[Solved] K8s cannot delete the namespace. It is always in the terminating state.

Problem phenomenon:

After kubectl delete ns XXXX, the namespace is always in the terminating state.

Use: kubectl delete ns monitoring — grace period = 0 – force cannot be deleted

Error message:

warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.

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


1. Export namespace information

kubectl get namespace monitoring -o json > monitoring.json

2. Delete the contents under spec in JSON file

The purpose of this step is to clear the content and overwrite the original ns with the ns of the empty content, so as to ensure that the NS content to be deleted is empty and the deletion command cannot be blocked

3. Overlay the empty namespace into the k8s cluster through the API server interface

curl -k -H “Content-Type: application/json” -X PUT –data-binary @monitoring.json

4. For clusters without authentication, you can perform steps 1-3. For those with authentication, you need to use Kube proxy to proxy:

Open k8s two windows of the master node,
Execute kubectl proxy in one window
Execute in another window: curl – K – H “content type: application/JSON” – x put — data binary @ monitoring.json

Similar Posts: