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

 

posted on 2019-11-04 16:49  光阴8023  阅读(2098)  评论(0编辑  收藏  举报