k8s 無法刪除namespace,一直處於Terminating的狀態解決方案


問題現象:

kubectl delete ns XXXX 后, namespace 一直處於 Terminating 狀態。

使用:kubectl delete ns monitoring --grace-period=0 –force 也無法刪除

報錯信息:

warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.

Error from server (Conflict): Operation cannot be fulfilled on namespaces " monitoring ": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.

解決方法:

1.將namespace信息導出

  kubectl get namespace monitoring -o json > monitoring.json

2.將json文件中 spec 下的內容刪除

   這一步驟的目的在於將內容清空后,以空內容的ns覆蓋原有ns,這樣保證了要刪除的ns內容為空,刪除的命令也就無法阻塞了

3.將具體內容為空的 namespace ,通過 api-server 接口,覆蓋到k8s集群中

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

4.無認證的集群執行1-3步即可,針對有認證的情況,需要使用 kube-proxy 進行代理:

  打開k8s主節點的兩個窗口,
  在一個窗口中執行 kubectl proxy
  另一個窗口中執行:curl -k -H "Content-Type: application/json" -X PUT --data-binary @monitoring.json http://127.0.0.1:8081/api/v1/namespaces/monitoring/finalize

參考博文:

https://blog.csdn.net/Jerry_Pan1990/article/details/103633627


免責聲明!

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



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