kubernetes無法刪除namespace提示Terminating


刪除命名空間namespace經常遇到這個問題

https://blog.csdn.net/weixin_44774358/article/details/97134277

https://blog.csdn.net/tongzidane/article/details/88988542

 

[root@k8s-master scripts]#kubectl   get ns
NAME STATUS AGE default Active 4d2h demo
-project Active 3d2h istio-system Active 4d kube-node-lease Active 4d2h kube-public Active 4d2h kube-system Active 4d2h kubesphere-alerting-system Terminating 4d kubesphere-controls-system Active 4d kubesphere-devops-system Active 4d kubesphere-logging-system Active 4d kubesphere-monitoring-system Active 4d kubesphere-system Active 4d1h openpitrix-system Active 4d [root@k8s-master scripts]#
kubectl get namespace kubesphere-alerting-system -o json > tmp.json

先拿到當前namespace描述,然后打開tmp.json,刪除其中的spec字段。因為這邊的K8s集群是帶認證的,

# cat tmp.json
{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "annotations": {
            "openpitrix_runtime": "runtime-Jk8rM7AQG4ZZ"
        },
        "creationTimestamp": "2019-10-31T08:02:16Z",
        "deletionGracePeriodSeconds": 0,
        "deletionTimestamp": "2019-11-04T08:42:37Z",
        "finalizers": [
            "finalizers.kubesphere.io/namespaces"  #記得要完全刪除字段中的內容
        ],
        "labels": {
            "kubesphere.io/workspace": "system-workspace"
        },
        "name": "kubesphere-controls-system",
        "ownerReferences": [
            {
                "apiVersion": "tenant.kubesphere.io/v1alpha1",
                "blockOwnerDeletion": true,
                "controller": true,
                "kind": "Workspace",
                "name": "system-workspace",
                "uid": "fcb1cebf-7fe2-4b36-b10e-0d864a52a921"
            }
        ],
        "resourceVersion": "780521",
        "selfLink": "/api/v1/namespaces/kubesphere-controls-system",
        "uid": "553620bf-3efc-46a3-ac14-f4f37bf43470"
    },
    "spec": {},
    "status": {
        "phase": "Terminating"
    }
}

記得要完全刪除字段中的內容

要先克隆一個新會話,執行

kubectl proxy --port=8081

新開了窗口運行kubectl proxy跑一個API代理在本地的8081端口。

# kubectl proxy --port=8081
Starting to serve on 127.0.0.1:8081

執行

curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8081/api/v1/namespaces/kubesphere-alerting-system/finalize
# kubectl get namespace
NAME                           STATUS   AGE
default                        Active   4d2h
demo-project                   Active   3d2h
istio-system                   Active   4d
kube-node-lease                Active   4d2h
kube-public                    Active   4d2h
kube-system                    Active   4d2h
kubesphere-devops-system       Active   4d
kubesphere-logging-system      Active   4d
kubesphere-monitoring-system   Active   4d
kubesphere-system              Active   4d1h
openpitrix-system              Active   4d

 


免責聲明!

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



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