k8s的pod或者ns资源一直terminating删除办法

假设你要删掉的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

好了就可以删掉了!

猜你喜欢

转载自www.cnblogs.com/xiaoyaojinzhazhadehangcheng/p/12067283.html