九析帶你輕鬆完爆 k8s 刪除 namespace 卡在 terminating

目錄git

1 解決方案綜述json

2 錯誤描述api

3 解決方案服務器

    3.1 導出 ns 資源定義restful

    3.2 編輯 ns 資源定義app

    3.3 建立代理服務器curl

    3.4 curl 調用刪除 nside


1 解決方案綜述gitlab

        建立本地代理服務器,而後經過 curl 客戶端調用 http restful api 強行刪除 namespace。this

2 錯誤描述

        刪除 ns 時(本文是 gitlab-ce,我的根據實際狀況修改),發現長期處於 「terminating」 狀態:

spacer.gif1.png

        因而執行以下語句強行刪除:

kubectl delete ns gitlab-ce --force --grace-period=0

        出現以下錯誤:

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

3 解決方案

3.1 導出 ns 資源定義

kubectl get ns gitlab-ce -o json > gitlab-ce.json

3.2 編輯 ns 資源定義

        打開 gitlab-ce.json 資源文件,而後刪除其中的 spec 字段(由於其中會包括 finalizers 字段)。spacer.gifclipboard2.png

3.3 建立代理服務器

        在本地和 k8s apiserver 之間建立代理服務器,後續會將刪除 namespace 的 api 經過代理服務器端口(默認8001)轉發到遠程 k8s apiserver 服務器處理。

kubectl proxy

clipboard3.pngspacer.gif

3.4 curl 調用刪除 ns

        執行 curl 客戶端調用,刪除 ns。

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

clipboard4.png

        自此,輕鬆完爆處於 terminating 狀態的 namespace。

相關文章
相關標籤/搜索