1,namespace Terminating状态处理
在k8s集群中进行测试删除namespace是经常的事件,而为了方便操作,一般都是直接对整个名称空间进行删除操作。$ kubectl get ns qasim NAME STATUS AGE qasim Terminating 24d
调用接口删除
开启一个代理终端 $ kubectl proxy Starting to serve on 127.0.0.1:8001
再开启一个操作终端
将test namespace的配置文件输出保存 $ kubectl get ns qasim -o json > qasim.json
删除spec下finalizers的内容及status部分的内容还有metadata字段后的","号,切记! 剩下内容大致如下:
{ "apiVersion": "v1", "kind": "Namespace", "metadata": { "annotations": { "cattle.io/status": "{\"Conditions\":[{\"Type\":\"ResourceQuotaInit\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2020-10-09T07:12:17Z\"},{\"Type\":\"InitialRolesPopulated\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2020-10-09T07:12:18Z\"}]}", "lifecycle.cattle.io/create.namespace-auth": "true" }, "creationTimestamp": "2020-10-09T07:12:16Z", "deletionTimestamp": "2020-10-09T07:12:22Z", "name": "qasim", "resourceVersion": "471648079", "selfLink": "/api/v1/namespaces/test", "uid": "862d311e-d87a-48c2-bc48-332a4db9dbdb" } }
调接口删除
$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @qasim.json http://127.0.0.1:8001/api/v1/namespaces/qasim/finalize { "kind": "Namespace", "apiVersion": "v1", "metadata": { "name": "qasim", "uid": "fa898418-3a8c-4464-854c-3128ad7af3eb", "resourceVersion": "584891986", "creationTimestamp": "2021-12-16T03:00:34Z", "deletionTimestamp": "2022-04-11T07:59:18Z", "labels": { "kubernetes.io/metadata.name": "qasim" }, "managedFields": [ { "manager": "kubectl-create", "operation": "Update", "apiVersion": "v1", "time": "2021-12-16T03:00:34Z", "fieldsType": "FieldsV1", "fieldsV1": {"f:metadata":{"f:labels":{".":{},"f:kubernetes.io/metadata.name":{}}}} }, { "manager": "kube-controller-manager", "operation": "Update", "apiVersion": "v1", "time": "2022-04-11T07:59:32Z", "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":{}}}}} } ] }, "spec": { }, "status": { "phase": "Terminating", "conditions": [ { "type": "NamespaceDeletionDiscoveryFailure", "status": "True", "lastTransitionTime": "2022-04-11T07:59:26Z", "reason": "DiscoveryFailed", "message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request" }, { "type": "NamespaceDeletionGroupVersionParsingFailure", "status": "False", "lastTransitionTime": "2022-04-11T07:59:32Z", "reason": "ParsedGroupVersions", "message": "All legacy kube types successfully parsed" }, { "type": "NamespaceDeletionContentFailure", "status": "False", "lastTransitionTime": "2022-04-11T07:59:32Z", "reason": "ContentDeleted", "message": "All content successfully deleted, may be waiting on finalization" }, { "type": "NamespaceContentRemaining", "status": "False", "lastTransitionTime": "2022-04-11T07:59:32Z", "reason": "ContentRemoved", "message": "All content successfully removed" }, { "type": "NamespaceFinalizersRemaining", "status": "False", "lastTransitionTime": "2022-04-11T07:59:32Z", "reason": "ContentHasNoFinalizers", "message": "All content-preserving finalizers finished" } ] }
补充:删除rancher的相关namespace(谨慎操作!!!)
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 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 kubectl delete namespace local --grace-period=0 --force
2,pv Terminating状态处理
(1)可以执行如下命令强制删除(PV-NAME 替换成实际需要删除的 pv 名称):$ kubectl patch pv pv-name -p '{"metadata":{"finalizers":null}}'(2)再次查看可以发现该 pv 已被删除:
标签:status,kubectl,pv,--,namespace,Terminating,type,metadata From: https://www.cnblogs.com/qianyuliang/p/17402724.html