8

删除k8s中的命名空间

 3 years ago
source link: https://aimuke.github.io/k8s/2020/11/06/k8s-delete-namespace/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

删除k8s中的命名空间

kubernetes无法删除 namespace 提示 Terminating <a id="articleContentId"></a>

最近配置traefik时,想重新部署jenkins,出现如下问题

1
2
3
4
5
6
7
# ./kubectl get namespaces --kubeconfig ./conf/kubeconfig
NAME              STATUS        AGE
default           Active        27h
istio-system      Terminating   20h
kube-node-lease   Active        27h
kube-public       Active        27h
kube-system       Active        27h

解决方法如下:

1
# kubectl get namespace istio-system -o json > tmp.json

先运行 kubectl get namespace istio-system -o json > tmp.json,拿到当前 namespace 描述,然后打开 tmp.json ,删除其中的 spec 字段。

最后运行:

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
# curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8080/api/v1/namespaces/istio-system/finalize
{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "istio-system",
    "selfLink": "/api/v1/namespaces/istio-system/finalize",
    "uid": "713e2935-41eb-4e8f-be52-3b43a7536b4f",
    "resourceVersion": "29523",
    "creationTimestamp": "2020-09-08T11:18:34Z",
    "deletionTimestamp": "2020-09-09T07:18:05Z",
    "managedFields": [
      {
        "manager": "kubectl",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2020-09-08T11:18:34Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {"f:status":{"f:phase":{}}}
      }
    ]
  },
  "spec": {

  },
  "status": {
    "phase": "Terminating"
  }
}

至此,命名空间已经删除


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK