k8s -- 删除namespace时一直Terminating
删除ns,一直处于Terminating状态中:
[root@master1 tmp]# kubectl get ns | grep Terminating billing Terminating 92d istio-system Terminating 358d kubesphere-alerting-system Terminating 358d kubesphere-controls-system Terminating 358d kubesphere-devops-system Terminating 358d kubesphere-logging-system Terminating 358d kubesphere-monitoring-system Terminating 358d kubesphere-system Terminating 358d openpitrix-system Terminating 358d
解决方法:
#!/bin/bash ns_list=`kubectl get ns | grep Terminating|awk '{print $1}'` for nas in $ns_list do kubectl get ns $nas -o json > /tmp/$nas.json done
将json文件中的finalizers字段置空:
[root@master1 ~]# cat billing.json { "apiVersion": "v1", "kind": "Namespace", "metadata": { "annotations": { "kubesphere.io/creator": "xiongzw", "openpitrix_runtime": "runtime-XzRWj3JVyw9v" }, "creationTimestamp": "2020-07-10T01:41:49Z", "deletionGracePeriodSeconds": 0, "deletionTimestamp": "2020-09-29T06:54:40Z", "finalizers": [ "finalizers.kubesphere.io/namespaces" #清空finalizers字段中内容 ], "labels": { "kubesphere.io/workspace": "asiainfo" }, "name": "billing", "ownerReferences": [ { "apiVersion": "tenant.kubesphere.io/v1alpha1", "blockOwnerDeletion": true, "controller": true, "kind": "Workspace", "name": "asiainfo", "uid": "d274f81e-f154-11e9-a4c3-fa163ea525b1" } ], "resourceVersion": "144469004", "selfLink": "/api/v1/namespaces/billing", "uid": "85bc6392-c24e-11ea-b466-fa163ea525b1" }, "spec": {}, #删除spec字段中的相关内容 "status": { "phase": "Terminating" } }
全部修改完毕后,执行下面脚本:
[root@master1 tmp]# cat del.sh #!/bin/bash kubectl proxy --port=8081 & ns_list=`kubectl get ns | grep Terminating|awk '{print $1}'` for nas in $ns_list do curl -k -H "Content-Type: application/json" -X PUT --data-binary @$nas.json http://127.0.0.1:8081/api/v1/namespaces/$nas/finalize done
查看namespace状态:
[root@master1 deploy]# kubectl get ns NAME STATUS AGE corecrm Active 357d default Active 358d kube-node-lease Active 358d kube-public Active 358d kube-system Active 358d showenv Active 210d smartenv Active 189d
所有Terminating状态的namespace都已删除。