k8s的namespace一直Terminating的完美解決方案

k8s的namespace一直Terminating的完美解決方案

在k8s集羣中進行測試刪除namespace是常常的事件,而爲了方便操做,通常都是直接對整個名稱空間進行刪除操做。
相信道友們在進行此步操做的時候,會遇到要刪除的namespace一直處於Terminating。下面我將給出一個完美的解決方案,json

測試demo

建立demo namespace
# kubectl create ns test
namespace/test created

刪除demo namespace
# kubectl delete ns test
namespace "test" deleted

一直處於deleted不見exit
查看狀態 可見test namespace 處於Terminating  
# kubectl get ns -w
NAME                STATUS        AGE
test                Terminating   18s

下面給出一種完美的解決方案:調用接口刪除

開啓一個代理終端
# kubectl proxy
Starting to serve on 127.0.0.1:8001

再開啓一個操做終端
將test namespace的配置文件輸出保存
# kubectl get ns test -o json > test.json
刪除spec及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": "test",
        "resourceVersion": "471648079",
        "selfLink": "/api/v1/namespaces/test",
        "uid": "862d311e-d87a-48c2-bc48-332a4db9dbdb"
    }
}

調接口刪除
# curl -k -H "Content-Type: application/json" -X PUT --data-binary @test.json http://127.0.0.1:8001/api/v1/namespaces/test/finalize
{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "test",
    "selfLink": "/api/v1/namespaces/test/finalize",
    "uid": "862d311e-d87a-48c2-bc48-332a4db9dbdb",
    "resourceVersion": "471648079",
    "creationTimestamp": "2020-10-09T07:12:16Z",
    "deletionTimestamp": "2020-10-09T07:12:22Z",
    "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"
    }
  },
  "spec": {

  },
  "status": {
    "phase": "Terminating",
    "conditions": [
      {
        "type": "NamespaceDeletionDiscoveryFailure",
        "status": "True",
        "lastTransitionTime": "2020-10-09T07:12:27Z",
        "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": "2020-10-09T07:12:28Z",
        "reason": "ParsedGroupVersions",
        "message": "All legacy kube types successfully parsed"
      },
      {
        "type": "NamespaceDeletionContentFailure",
        "status": "False",
        "lastTransitionTime": "2020-10-09T07:12:28Z",
        "reason": "ContentDeleted",
        "message": "All content successfully deleted"
      }
    ]
  }
}

查看結果

一、delete 狀態終止
kubectl delete ns test
namespace "test" deleted

二、Terminating狀態終止
kubectl get ns -w
test                Terminating   18s
test                Terminating   17m

名稱空間被刪除掉api

相關文章
相關標籤/搜索