假設你要刪掉的ns資源,發現一直刪不了處於terminating狀態
1.首先試一下先把這個ns的所有pod都刪掉
kubectl delete pod --all -n <terminating-namespace>
2.還是不行的話
kubectl delete pod --grace-period=0 –force
3.如果還是不行就要來必殺技了
3.1首先生成一個tmp.json文件
kubectl get namespace <terminating-namespace> -o json >tmp.json
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: 2019-11-19T18:48:30Z
deletionTimestamp: 2019-11-19T18:59:36Z
name: <terminating-namespace>
resourceVersion: "1385077"
selfLink: /api/v1/namespaces/<terminating-namespace>
uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5
spec:
finalizers:
- kubernetes
status:
phase: Terminating
3.2然后修改這個json文件,把finalizers的kubernetes刪掉
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: 2019-11-19T18:48:30Z
deletionTimestamp: 2019-11-19T18:59:36Z
name: <terminating-namespace>
resourceVersion: "1385077"
selfLink: /api/v1/namespaces/<terminating-namespace>
uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5
spec:
finalizers:
-
status:
phase: Terminating
3.3然后把本機服務暴露在本地端口的8001端口上
kubectl proxy
結果:
Starting to serve on 127.0.0.1:8001
新開一個terminal,把修改后的tmp.json到要刪除的ns資源目錄下
curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize
好了就可以刪掉了!