如何删除顽疾Terminating状态的namespace
删除Terminating状态的namespace
话不多说, 开整
- 获取ns
kubectl get ns NAME STATUS AGE arms-prom Active 16d cattle-impersonation-system Terminating 13d default Active 16d kube-node-lease Active 16d kube-public Active 16d kube-system Active 16d local Active 13d rabbitmq-system Active 15d sit Active 15d
- 获取问题状态的namespace的运行时json描述文件
kubectl get namespace cattle-impersonation-system -o json > cattle-impersonation-system.json
- 使用文本编辑器,打开
cattle-impersonation-system.json
文件,查找 "finalizers" 部分,如果该部分存在任何条目(例如 "finalizers": ["controller.cattle.io/namespace-auth"]),将它们删除,保存并关闭文件。 - 修改完成城后, 执行如下命令
kubectl replace --raw "/api/v1/namespaces/cattle-impersonation-system/finalize" -f cattle-impersonation-system.json {"kind":"Namespace","apiVersion":"v1","metadata":{"name":"cattle-impersonation-system","uid":"fa5e737e-0696-4793-a933-61d456bc1505","resourceVersion":"12283112","creationTimestamp":"2024-06-24T12:55:02Z","deletionTimestamp":"2024-07-08T02:18:32Z","deletionGracePeriodSeconds":0,"labels":{"authz.cluster.cattle.io/impersonator":"true","cattle.io/creator":"norman","field.cattle.io/projectId":"p-fn8f6","kubernetes.io/metadata.name":"cattle-impersonation-system"},"annotations":{"cattle.io/status":"{\"Conditions\":[{\"Type\":\"ResourceQuotaInit\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2024-06-24T12:55:03Z\"},{\"Type\":\"InitialRolesPopulated\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2024-06-24T12:55:08Z\"}]}","field.cattle.io/projectId":"c-m-rr5zzdd7:p-fn8f6","lifecycle.cattle.io/create.namespace-auth":"true","management.cattle.io/no-default-sa-token":"true"},"managedFields":[{"manager":"rancher","operation":"Update","apiVersion":"v1","time":"2024-06-24T12:55:07Z","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:cattle.io/status":{},"f:field.cattle.io/projectId":{},"f:lifecycle.cattle.io/create.namespace-auth":{},"f:management.cattle.io/no-default-sa-token":{}},"f:labels":{".":{},"f:authz.cluster.cattle.io/impersonator":{},"f:cattle.io/creator":{},"f:kubernetes.io/metadata.name":{}}}}},{"manager":"agent","operation":"Update","apiVersion":"v1","time":"2024-06-24T12:59:51Z","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{"f:field.cattle.io/projectId":{}}}}},{"manager":"kube-controller-manager","operation":"Update","apiVersion":"v1","time":"2024-07-08T02:18:39Z","fieldsType":"FieldsV1","fieldsV1":{"f:status":{"f:conditions":{".":{},"k:{\"type\":\"NamespaceContentRemaining\"}":{".":{},"f:lastTransitionTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}},"k:{\"type\":\"NamespaceDeletionContentFailure\"}":{".":{},"f:lastTransitionTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}},"k:{\"type\":\"NamespaceDeletionDiscoveryFailure\"}":{".":{},"f:lastTransitionTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}},"k:{\"type\":\"NamespaceDeletionGroupVersionParsingFailure\"}":{".":{},"f:lastTransitionTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}},"k:{\"type\":\"NamespaceFinalizersRemaining\"}":{".":{},"f:lastTransitionTime":{},"f:message":{},"f:reason":{},"f:status":{},"f:type":{}}}}},"subresource":"status"}]},"spec":{},"status":{"phase":"Terminating","conditions":[{"type":"NamespaceDeletionDiscoveryFailure","status":"False","lastTransitionTime":"2024-07-08T02:18:38Z","reason":"ResourcesDiscovered","message":"All resources successfully discovered"},{"type":"NamespaceDeletionGroupVersionParsingFailure","status":"False","lastTransitionTime":"2024-07-08T02:18:38Z","reason":"ParsedGroupVersions","message":"All legacy kube types successfully parsed"},{"type":"NamespaceDeletionContentFailure","status":"False","lastTransitionTime":"2024-07-08T02:18:38Z","reason":"ContentDeleted","message":"All content successfully deleted, may be waiting on finalization"},{"type":"NamespaceContentRemaining","status":"False","lastTransitionTime":"2024-07-08T02:18:38Z","reason":"ContentRemoved","message":"All content successfully removed"},{"type":"NamespaceFinalizersRemaining","status":"False","lastTransitionTime":"2024-07-08T02:18:38Z","reason":"ContentHasNoFinalizers","message":"All content-preserving finalizers finished"}]}}
- 再次查看namespace是否被删除 kubectl get ns