本文主要是介绍解决k8s删除命名空间时一直报错terminated无法成功删除的故障,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
故障现象如下:
在启动dashboard的时候报错,之前删除过一次,再次创建无法创建
查看命名空间状态为Terminating
强制删除也没有用
解决方法:
先将namespace的配置文件输出保存
[root@master01 k8s]# kubectl get ns kubernetes-dashboard -o json > tmp.json
删除spec及status部分的内容,剩下内容如下
[root@master01 k8s]# vim tmp.json {"apiVersion": "v1","kind": "Namespace","metadata": {"annotations": {"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"kubernetes-dashboard\"}}\n"},"creationTimestamp": "2020-10-08T12:11:06Z","deletionTimestamp": "2020-10-09T03:22:56Z","name": "kubernetes-dashboard","resourceVersion": "311861","selfLink": "/api/v1/namespaces/kubernetes-dashboard","uid": "57df1ddf-095f-11eb-89f9-000c29f4bf17"}}
启动代理:
[root@master01 k8s]# kubectl proxy
Starting to serve on 127.0.0.1:8001
调用接口删除
[root@master01 k8s]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/finalize
{"kind": "Namespace","apiVersion": "v1","metadata": {"name": "kubernetes-dashboard","selfLink": "/api/v1/namespaces/kubernetes-dashboard/finalize","uid": "57df1ddf-095f-11eb-89f9-000c29f4bf17","resourceVersion": "313388","creationTimestamp": "2020-10-08T12:11:06Z","deletionTimestamp": "2020-10-09T03:22:56Z","annotations": {"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"kubernetes-dashboard\"}}\n"}},"spec": {},"status": {"phase": "Terminating"}
}
查看命名空间已成功删除
[root@master01 k8s]# kubectl get ns
NAME STATUS AGE
default Active 9d
kube-public Active 9d
kube-system Active 9d[root@master01 k8s]# kubectl get ns kubernetes-dashboard
Error from server (NotFound): namespaces "kubernetes-dashboard" not found
这篇关于解决k8s删除命名空间时一直报错terminated无法成功删除的故障的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!