介紹
最近一直在玩 EKS(Elastic Kubernetes Service -- Amazon EKS) 和 KubeSphere, 因為之前沒有使用過 EKS 和 KubeSphere,所以這個程序也是一個試錯的程序,在我使用 KubeSphere 的時候發現有一個日志服務,在好奇心的驅使下,我創建了它,
在我創建了日志服務(KubeSphere Logging System)以后,我發現我并不想使用它,(可能我只是想看看它到底是什么吧,)強迫癥的我就想把它給洗掉掉,于是我在我的 EKS 中對他進行了強制洗掉:
$ kubectl delete ns kubesphere-logging-system --force --grace-period=0
讓人尷尬的是,這個 Namespace 并沒有立馬洗掉,我自我安慰道,可能 Namespace 下邊有其他沒有洗掉的資源在等待洗掉,我再等等,,,
過了半個小時,再次查看洗掉進度:
$ kubectl get ns kubesphere-logging-system
NAME STATUS AGE
kubesphere-logging-system Terminating 6d19h
它好像這地卡在了 Terminating 的狀態,我試著尋找解決方法,參考這個 isue:http://github.com/kubernetes/kubernetes/issues/60807,但是這種方法要通過 API 才可以實作,EKS 是托管在 AWS 中的,我根本沒有辦法去操作 EKS 的后臺,
終于我在這個 issue 中找到了答案:https://github.com/kubernetes/kubernetes/issues/60807#issuecomment-663853215
如何徹底洗掉 namespace
獲取 namespace 的詳情資訊并轉為 json
$ kubectl get namespace kubesphere-logging-system -o json > kubesphere-logging-system.json
打開 json 檔案編輯
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2021-12-31T05:03:58Z",
"deletionTimestamp": "2022-01-05T08:05:40Z",
"labels": {
"kubesphere.io/namespace": "kubesphere-logging-system",
"kubesphere.io/workspace": "system-workspace"
},
"managedFields": [
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:labels": {
".": {},
"f:kubesphere.io/namespace": {}
},
"f:ownerReferences": {
".": {},
"k:{\"uid\":\"6d535470-2592-4f3c-a155-eabc362c339d\"}": {
".": {},
"f:apiVersion": {},
"f:blockOwnerDeletion": {},
"f:controller": {},
"f:kind": {},
"f:name": {},
"f:uid": {}
}
}
}
},
"manager": "controller-manager",
"operation": "Update",
"time": "2021-12-31T05:04:01Z"
},
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:labels": {
"f:kubesphere.io/workspace": {}
}
},
"f:status": {
"f:phase": {}
}
},
"manager": "kubectl",
"operation": "Update",
"time": "2021-12-31T05:04:01Z"
},
{
"apiVersion": "v1",
"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": {}
}
}
}
},
"manager": "kube-controller-manager",
"operation": "Update",
"time": "2022-01-05T08:05:47Z"
}
],
"name": "kubesphere-logging-system",
"ownerReferences": [
{
"apiVersion": "tenant.kubesphere.io/v1alpha1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "Workspace",
"name": "system-workspace",
"uid": "6d535470-2592-4f3c-a155-eabc362c339d"
}
],
"resourceVersion": "7376520",
"uid": "2b76e9b1-75f2-4a2e-a819-73b36aea188e"
},
"spec": {
"finalizers": [
"kubernetes" # 將此行洗掉
]
},
"status": {
"conditions": [
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "All resources successfully discovered",
"reason": "ResourcesDiscovered",
"status": "False",
"type": "NamespaceDeletionDiscoveryFailure"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "All legacy kube types successfully parsed",
"reason": "ParsedGroupVersions",
"status": "False",
"type": "NamespaceDeletionGroupVersionParsingFailure"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "All content successfully deleted, may be waiting on finalization",
"reason": "ContentDeleted",
"status": "False",
"type": "NamespaceDeletionContentFailure"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "Some resources are remaining: fluentbits.logging.kubesphere.io has 1 resource instances",
"reason": "SomeResourcesRemain",
"status": "True",
"type": "NamespaceContentRemaining"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "Some content in the namespace has finalizers remaining: fluentbit.logging.kubesphere.io in 1 resource instances",
"reason": "SomeFinalizersRemain",
"status": "True",
"type": "NamespaceFinalizersRemaining"
}
],
"phase": "Terminating"
}
}
找到 spec 將 finalizers 下的 kubernetes 洗掉,
具體如下
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2021-12-31T05:03:58Z",
"deletionTimestamp": "2022-01-05T08:05:40Z",
"labels": {
"kubesphere.io/namespace": "kubesphere-logging-system",
"kubesphere.io/workspace": "system-workspace"
},
"managedFields": [
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:labels": {
".": {},
"f:kubesphere.io/namespace": {}
},
"f:ownerReferences": {
".": {},
"k:{\"uid\":\"6d535470-2592-4f3c-a155-eabc362c339d\"}": {
".": {},
"f:apiVersion": {},
"f:blockOwnerDeletion": {},
"f:controller": {},
"f:kind": {},
"f:name": {},
"f:uid": {}
}
}
}
},
"manager": "controller-manager",
"operation": "Update",
"time": "2021-12-31T05:04:01Z"
},
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:labels": {
"f:kubesphere.io/workspace": {}
}
},
"f:status": {
"f:phase": {}
}
},
"manager": "kubectl",
"operation": "Update",
"time": "2021-12-31T05:04:01Z"
},
{
"apiVersion": "v1",
"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": {}
}
}
}
},
"manager": "kube-controller-manager",
"operation": "Update",
"time": "2022-01-05T08:05:47Z"
}
],
"name": "kubesphere-logging-system",
"ownerReferences": [
{
"apiVersion": "tenant.kubesphere.io/v1alpha1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "Workspace",
"name": "system-workspace",
"uid": "6d535470-2592-4f3c-a155-eabc362c339d"
}
],
"resourceVersion": "7376520",
"uid": "2b76e9b1-75f2-4a2e-a819-73b36aea188e"
},
"spec": {
"finalizers": [
]
},
"status": {
"conditions": [
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "All resources successfully discovered",
"reason": "ResourcesDiscovered",
"status": "False",
"type": "NamespaceDeletionDiscoveryFailure"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "All legacy kube types successfully parsed",
"reason": "ParsedGroupVersions",
"status": "False",
"type": "NamespaceDeletionGroupVersionParsingFailure"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "All content successfully deleted, may be waiting on finalization",
"reason": "ContentDeleted",
"status": "False",
"type": "NamespaceDeletionContentFailure"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "Some resources are remaining: fluentbits.logging.kubesphere.io has 1 resource instances",
"reason": "SomeResourcesRemain",
"status": "True",
"type": "NamespaceContentRemaining"
},
{
"lastTransitionTime": "2022-01-05T08:05:47Z",
"message": "Some content in the namespace has finalizers remaining: fluentbit.logging.kubesphere.io in 1 resource instances",
"reason": "SomeFinalizersRemain",
"status": "True",
"type": "NamespaceFinalizersRemaining"
}
],
"phase": "Terminating"
}
}
執行清理命令
現在我們只需要一條命令 就可以徹底洗掉這個 Namespace,
$ kubectl replace --raw "/api/v1/namespaces/kubesphere-logging-system/finalize" -f ./kubesphere-logging-system.json
執行完以后,你需要等待一會,再次執行命令檢查 Namespace,
$ kubectl replace --raw "/api/v1/namespaces/kubesphere-logging-system/finalize" -f ./kubesphere-logging-system.json
最后的檢查
$ kubectl get ns kubesphere-logging-system
Error from server (NotFound): namespaces "kubesphere-logging-system" not found
$ kubectl get ns
NAME STATUS AGE
default Active 23d
kubesphere-controls-system Active 9d
kubesphere-devops-system Active 9d
kubesphere-devops-worker Active 16h
kubesphere-monitoring-federated Active 9d
kubesphere-monitoring-system Active 9d
kubesphere-sample-dev Active 8d
kubesphere-system Active 9d
再次查看的時候,它已經不存在了,
本文由博客一文多發平臺 OpenWrite 發布!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/447060.html
標籤:其他
