k8s如何刪除處於terminating狀態的ns資源


假設你要刪掉兩個ns資源,發現一直刪不了處於terminating狀態

首先試一下先把這個ns的所有pod都刪掉

kubectl delete pod --all -n istio-system

還是不行的話,加個參數強制刪除

kubectl delete pod --grace-period=0 –force 

如果依然是卡死狀態,就要使用下面的必殺技了

首先生成一個tmp.json文件

 kubectl get namespace <terminating-namespace> -o json >tmp.json

 apiVersion: v1
 kind: Namespace
 metadata:
   creationTimestamp: 2018-11-19T18:48:30Z
   deletionTimestamp: 2018-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

然后修改這個json文件,把finalizers的kubernetes刪掉

 apiVersion: v1
 kind: Namespace
 metadata:
   creationTimestamp: 2018-11-19T18:48:30Z
   deletionTimestamp: 2018-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

然后把本機服務暴露在本地端口的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

這樣就可以刪掉了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM