Kubernetes Namespaces

Kubernetes Namespaces stuck in Terminating State

I have been working on Kubernetes for quite some time now and i am planning of writing blogs about issues which made me google the hell out.

To start the series, I am gonna write about the most common and annoying issue which i faced early on was the namespaces getting stuck in terminating state which wont budge even after clearing everything inside it.

Simple steps to fix it:

  1. Fetch the namespace details in a json file.
    Replace <namespace> with the namespace you are trying to delete
kubectl get namespaces <namespace> -ojson > tmp.json

2. Edit the tmp.json file generated in previous step and remove all elements from finalizers list. Have just an empty finalizers list.

"finalizers": [
],"name": "badmac","resourceVersion": "74124342","selfLink": "/api/v1/namespaces/badmac","uid": "2fc7b7c3-ac4f-4a29-8832-14cfca1c1146"},"spec": {"finalizers": []},

4. Create a proxy to fire a Kubernetes API call to update the namespace.

kubectl proxy

5. In another terminal window, fire the following command from the same path as your tmp.json file.
Don't forget to replace the <namespace> with the namespace you are trying to delete.

curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json<namespace>/finalize



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store