Skip to content

Commit dc9ba9e

Browse files
How to delete namespace stuck in terminating state
1 parent b95cb0f commit dc9ba9e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

k8s-ns-delete.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### 1. This command (with kubectl 1.11+) will show you what resources remain in the namespace:
2+
3+
```sh
4+
$ kubectl api-resources --verbs=list --namespaced -o name \
5+
| xargs -n 1 kubectl get --show-kind --ignore-not-found -n <namespace>
6+
```
7+
8+
### 2. Force-delete the namespace (perhaps leaving dangling resources):
9+
10+
```sh
11+
$ NAMESPACE=your-rogue-namespace
12+
13+
$ kubectl proxy & (for auth purposes)
14+
15+
$ kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' > temp.json
16+
17+
$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
18+
19+
```
20+
21+
### 3. This way you will not have to spawn a kubectl proxy process and avoid dependency with curl
22+
23+
```sh
24+
kubectl get namespace "stucked-namespace" -o json \
25+
| tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
26+
| kubectl replace --raw /api/v1/namespaces/stucked-namespace/finalize -f -
27+
28+
29+
```

0 commit comments

Comments
 (0)