namespace,pv 一直Terminating状态处理
1,namespace Terminating状态处理
在k8s集群中进行测试删除namespace是经常的事件,而为了方便操作,一般都是直接对整个名称空间进行删除操作。
1 2 3 | $ 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字段后的","号,切记!
剩下内容大致如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "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" } } |
调接口删除
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | $ 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 已被删除:
每天记录一点,就能多学一点,充实一点
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
2017-05-15 django从1.7升级到1.9后 提示:RemovedInDjango110Warning
2017-05-15 关闭TCP中135、139、445、593、1025 等端口的操作方法 (转)(记录下)