问题现象:
删除namespace,一直处于Terminating,并且用--force --grace-period=0 也删除不了
develop Terminating 4d9h
Error from server (Conflict): error when deleting "ns.yaml": Operation cannot be fulfilled on namespaces "develop": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.
解决方案:
Step1:查看namespace 是否还是Terminating
kubectl get namespaces
Step2: 查看yaml文件 ,finalizers是 - kubernetes
kubectl get namespace <terminating-namespace> -o yaml
apiVersion: v1 kind: Namespace metadata: creationTimestamp: 2020-05-20T18:48:30Z deletionTimestamp: 2020-05-20T18:59:36Z name: develop resourceVersion: "1385077" selfLink: /api/v1/namespaces/<terminating-namespace> uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5 spec: finalizers: - kubernetes status: phase: Terminating
Step3:获取namespace的json文件
kubectl get namespace <terminating-namespace> -o json >tmp.json
{ "apiVersion": "v1", "kind": "Namespace", "metadata": { "creationTimestamp": "2020-05-20T18:48:30Z", "deletionTimestamp": "2020-05-20T18:59:36Z", "name": "<terminating-namespace>", "resourceVersion": "1385077", "selfLink": "/api/v1/namespaces/<terminating-namespace>", "uid": "b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5" }, "spec": { "finalizers": }, "status": { "phase": "Terminating" } }
Step4:修改json文件,将finalizers去掉
{ "apiVersion": "v1", "kind": "Namespace", "metadata": { "annotations": { "scheduler.alpha.kubernetes.io/node-selector": "scen=kuai-develop,user=kuai-all" }, "creationTimestamp": "2020-05-20T05:30:21Z", "deletionTimestamp": "2020-05-20T04:22:14Z", "name": "develop", "resourceVersion": "388130567", "selfLink": "/api/v1/namespaces/kuai-develop", "uid": "2b967bf4-966d-11ea-885f-246e967d5d94" }, "spec": { }, "status": { "phase": "Terminating" } }
Step5:执行命令
curl -k -H "Authorization: Bearer ${token}" -H "Content-Type: application/json" -X PUT --data-binary @tmp.json https://10.196.0.1:443/api/v1/namespaces/${namespace}/finalize
参考:https://www.ibm.com/support/knowledgecenter/en/SSBS6K_3.1.1/troubleshoot/ns_terminating.html