正常删除namespace(kubernetes-dashboard)一直删不干净,处于Terminating状态
正常删除
kubectl delete namespace NAMESPACENAME
强制删除
kubectl delete namespace NAMESPACENAME --force --grace-period=0
如果强制删除也没有用的话
修改finalizers,删除下面红色框内容
kubectl edit namespace NAMESPACE_NAME
如果这个方法也不行的话
通过调用接口删除
导出json格式到tmp.json
kubectl get namespace <terminating-namespace> -o json >tmp.json
编辑tmp.josn,删除finalizers 字段的值
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"kubernetes-dashboard\"}}\n"
},
"creationTimestamp": "2022-05-29T14:35:19Z",
"deletionTimestamp": "2022-05-30T06:51:16Z",
"name": "kubernetes-dashboard",
"resourceVersion": "1048583",
"selfLink": "/api/v1/namespaces/kubernetes-dashboard",
"uid": "2320611c-1eec-4903-80e9-e30850b9b5c7"
},
"spec": {
"finalizers": []
},
"status": {
"phase": "Terminating"
}
}
开启 proxy
kubectl proxy
打开新的terminal 窗口,运行以下命令:
curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize