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 已被洗掉:
每天記錄一點,就能多學一點,充實一點
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/552528.html
標籤:其他
下一篇:返回列表
