Delete stuck Namespace

Delete stuck NS

Manually delete a terminating namespace If the issue is not resolved, you can manually delete your namespace that is stuck in the Terminating state.

View the namespaces that are stuck in the Terminating state:

kubectl get namespaces

Select a terminating namespace and view the contents of the namespace to find out the finalizer:

kubectl get namespace -o yaml

Your YAML contents might resemble the following output:

 1 apiVersion: v1
 2 kind: Namespace
 3 metadata:
 4   creationTimestamp: 2018-11-19T18:48:30Z
 5   deletionTimestamp: 2018-11-19T18:59:36Z
 6   name: <terminating-namespace>
 7   resourceVersion: "1385077"
 8   selfLink: /api/v1/namespaces/<terminating-namespace>
 9   uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5
10 spec:
11   finalizers:
12   - kubernetes
13 status:
14   phase: Terminating

Create a temporary JSON file:

kubectl get namespace -o json >tmp.json

Edit your tmp.json file. Remove the kubernetes value from the finalizers field and save the file.

Your tmp.json file might resemble the following output:

 1  {
 2      "apiVersion": "v1",
 3      "kind": "Namespace",
 4      "metadata": {
 5          "creationTimestamp": "2018-11-19T18:48:30Z",
 6          "deletionTimestamp": "2018-11-19T18:59:36Z",
 7          "name": "<terminating-namespace>",
 8          "resourceVersion": "1385077",
 9          "selfLink": "/api/v1/namespaces/<terminating-namespace>",
10          "uid": "b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5"
11      },
12      "spec": {
13         "finalizers": 
14      },
15      "status": {
16          "phase": "Terminating"
17      }
18  }

To set a temporary proxy IP and port, run the following command. Be sure to keep your terminal window open until you delete the stuck namespace:

kubectl proxy

Your proxy IP and port might resemble the following output:

Starting to serve on 127.0.0.1:8001

From a new terminal window, make an API call with your temporary proxy IP and port:

curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces//finalize

Your output might resemble the following content:

 1 {
 2   "kind": "Namespace",
 3   "apiVersion": "v1",
 4   "metadata": {
 5     "name": "<terminating-namespace>",
 6     "selfLink": "/api/v1/namespaces/<terminating-namespace>/finalize",
 7     "uid": "b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5",
 8     "resourceVersion": "1602981",
 9     "creationTimestamp": "2018-11-19T18:48:30Z",
10     "deletionTimestamp": "2018-11-19T18:59:36Z"
11   },
12   "spec": {
13
14   },
15   "status": {
16     "phase": "Terminating"
17   }
18}

Note: The finalizer parameter is removed.

Verify that the terminating namespace is removed:

kubectl get namespaces

Continue to follow the steps for other namespaces that are stuck in the Terminating state.