问题现象:
kubectl delete ns XXXX 后, namespace 一直处于 Terminating 状态。
使用:kubectl delete ns monitoring --grace-period=0 –force 也无法删除
报错信息:
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
Error from server (Conflict): Operation cannot be fulfilled on namespaces " monitoring ": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.
解决方法:
1.将namespace信息导出
kubectl get namespace monitoring -o json > monitoring.json
2.将json文件中 spec 下的内容删除
这一步骤的目的在于将内容清空后,以空内容的ns覆盖原有ns,这样保证了要删除的ns内容为空,删除的命令也就无法阻塞了
3.将具体内容为空的 namespace ,通过 api-server 接口,覆盖到k8s集群中
curl -k -H "Content-Type: application/json" -X PUT --data-binary @monitoring.json http://127.0.0.1:8081/api/v1/namespaces/monitoring/finalize
4.无认证的集群执行1-3步即可,针对有认证的情况,需要使用 kube-proxy 进行代理:
打开k8s主节点的两个窗口,
在一个窗口中执行 kubectl proxy
另一个窗口中执行:curl -k -H "Content-Type: application/json" -X PUT --data-binary @monitoring.json http://127.0.0.1:8081/api/v1/namespaces/monitoring/finalize
参考博文:
https://blog.csdn.net/Jerry_Pan1990/article/details/103633627