问题:删除ns时一直显示terminating的状态
解决:
-
方法一:
通过强制删除,并且设置优雅删除时间为0(默认为30s)kubectl delete ns cattle-system --force --grace-period=0
实践后发现并不好使
-
方法二:
通过k8s提供的api接口,把.metadata.finalizers字段及其内容删除,从而k8s会直接将该ns删除$ kubectl get ns cattle-system -o json > cattle-system.json $ cat cattle-system.json { "apiVersion": "v1", "kind": "Namespace", "metadata": { "annotations": { "cattle.io/status": "{\"Conditions\":[{\"Type\":\"ResourceQuotaInit\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2022-04-19T04:11:00Z\"},{\"Type\":\"InitialRolesPopulated\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2022-04-19T04:11:06Z\"}]}", "field.cattle.io/projectId": "c-m-p9qpsm85:p-xxjt6", "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"cattle-system\"}}\n", "lifecycle.cattle.io/create.namespace-auth": "true", "management.cattle.io/no-default-sa-token": "true" }, "creationTimestamp": "2022-04-19T04:10:57Z", "deletionGracePeriodSeconds": 0, "deletionTimestamp": "2022-04-19T04:13:25Z", "finalizers": [ "controller.cattle.io/namespace-auth" ], "name": "cattle-system", "resourceVersion": "189264460", "selfLink": "/api/v1/namespaces/cattle-system", "uid": "b71ffd2d-bf96-11ec-a6c4-fa163eb86964" }, "spec": {}, "status": { "phase": "Terminating" } } $ kubectl proxy --port=8081(开启k8s apiserver的一个http代理,以免必须带上证书才能访问) $ curl -k -H "Content-Type: application/json" -X PUT --data-binary @cattle-system.json http://127.0.0.1:8081/api/v1/namespaces/cattle-system/finalize
经过第二种方法后,果然ns删除
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)