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 http://127.0.0.1:8001/api/v1/namespaces/<namespace>/finalize

--

--