【问题解决】k8s删除namespace一直处于Terminating
清理高可用安装的rancher时,遇到namespace无法delete删除,一直处于Terminating的状态。所以就寻找了各种方法解决。现整理如下:方法一:kubectl patch namespace cattle-system -p '{"metadata":{"finalizers":[]}}' --type='merge' -n cattle-systemkubectl delete
·
清理高可用安装的rancher时,遇到namespace无法delete删除,一直处于Terminating的状态。所以就寻找了各种方法解决。
现整理如下:
方法一:
kubectl patch namespace cattle-system -p '{"metadata":{"finalizers":[]}}' --type='merge' -n cattle-system
kubectl delete namespace cattle-system --grace-period=0 --force
kubectl patch namespace cattle-global-data -p '{"metadata":{"finalizers":[]}}' --type='merge' -n cattle-system
kubectl delete namespace cattle-global-data --grace-period=0 --force
kubectl patch namespace local -p '{"metadata":{"finalizers":[]}}' --type='merge' -n cattle-system
kubectl delete namespace local --grace-period=0 --force
for resource in `kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get -o name -n local`; do kubectl patch $resource -p '{"metadata": {"finalizers": []}}' --type='merge' -n local; done
方法二:
直接编辑namespace配置:
kubectl edit ns prom
删除spec和status配置项下的所有内容如:
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
},
"creationTimestamp": "2020-01-06T06:47:04Z",
"deletionTimestamp": "2020-02-11T04:11:57Z",
"name": "prom",
"resourceVersion": "9910052",
"selfLink": "/api/v1/namespaces/prom",
"uid": "59afb211-3050-11ea-af11-005056879c91"
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"phase": "Terminating"
}
}
修改后为
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
},
"creationTimestamp": "2020-01-06T06:47:04Z",
"deletionTimestamp": "2020-02-11T04:11:57Z",
"name": "prom",
"resourceVersion": "9910052",
"selfLink": "/api/v1/namespaces/prom",
"uid": "59afb211-3050-11ea-af11-005056879c91"
}
}
保存后即可验证删除。
方法三:
调用接口删除,同样清除spec和status内容
[root@master pos]# kubectl get ns prom -o json > tmp.json
[root@master pos]# vim tmp.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
},
"creationTimestamp": "2020-01-06T06:47:04Z",
"deletionTimestamp": "2020-02-11T04:11:57Z",
"name": "prom",
"resourceVersion": "9910052",
"selfLink": "/api/v1/namespaces/prom",
"uid": "59afb211-3050-11ea-af11-005056879c91"
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"phase": "Terminating"
}
}
启动代理
[root@master pos]# kubectl proxy
F0211 15:57:20.905914 4430 proxy.go:158] listen tcp 127.0.0.1:8001: bind: address already in use
调用接口
[root@master pos]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/prom/finalize
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "prom",
"selfLink": "/api/v1/namespaces/prom/finalize",
"uid": "59afb211-3050-11ea-af11-005056879c91",
"resourceVersion": "9937637",
"creationTimestamp": "2020-01-06T06:47:04Z",
"deletionTimestamp": "2020-02-11T04:11:57Z",
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
}
},
"spec": {
},
"status": {
"phase": "Terminating"
}
}[root@master pos]#
更多推荐
已为社区贡献11条内容
所有评论(0)