问题,namespace一直处于Terminating状态,无法删除

[root@master pos]# kubectl get ns
NAME              STATUS        AGE
bcia              Active        42d
data              Active        42d
default           Active        54d
ingress-nginx     Active        32d
kube-node-lease   Active        54d
kube-public       Active        54d
kube-system       Active        54d
monitoring        Active        41d
pos               Active        89m
prom              Terminating   36d
weave             Active        35d

1、正常删除

[root@master pos]# kubectl delete namespace prom
Error from server (Conflict): Operation cannot be fulfilled on namespaces "prom": The system is ensuring all content is removed from this namespace.  Upon completion, this namespace will automatically be purged by the system.

删除失败

2、强制删除

[root@master pos]# kubectl delete namespace prom --force --grace-period=0
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
Error from server (Conflict): Operation cannot be fulfilled on namespaces "prom": The system is ensuring all content is removed from this namespace.  Upon completion, this namespace will automatically be purged by the system.

删除失败

3、编辑删除
将finalizers内容删掉

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"name":"prom"}}
  creationTimestamp: "2020-01-06T06:47:04Z"
  deletionTimestamp: "2020-02-11T04:11:57Z"
  name: prom
  resourceVersion: "9910052"
  selfLink: /api/v1/namespaces/prom
  uid: 59afb211-3050-11ea-af11-005056879c91
spec:
  finalizers:
  - kubernetes
status:
  phase: Terminating

在这里插入图片描述
删除失败

4、调接口删除
1、将namespace的配置文件输出保存

[root@master pos]# kubectl get ns prom -o json > tmp.json
[root@master pos]# vim tmp.json
{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "annotations": {
            "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
        },
        "creationTimestamp": "2020-01-06T06:47:04Z",
        "deletionTimestamp": "2020-02-11T04:11:57Z",
        "name": "prom",
        "resourceVersion": "9910052",
        "selfLink": "/api/v1/namespaces/prom",
        "uid": "59afb211-3050-11ea-af11-005056879c91"
    },
    "spec": {
        "finalizers": [
            "kubernetes"
        ]
    },
    "status": {
        "phase": "Terminating"
    }
}

2、删除spec及status部分的内容,剩下内容如下:

{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "annotations": {
            "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
        },
        "creationTimestamp": "2020-01-06T06:47:04Z",
        "deletionTimestamp": "2020-02-11T04:11:57Z",
        "name": "prom",
        "resourceVersion": "9910052",
        "selfLink": "/api/v1/namespaces/prom",
        "uid": "59afb211-3050-11ea-af11-005056879c91"
    }
}

在这里插入图片描述
3、启动代理

[root@master pos]# kubectl proxy
F0211 15:57:20.905914    4430 proxy.go:158] listen tcp 127.0.0.1:8001: bind: address already in use

这里已经开启了代理

4、调接口删除

[root@master pos]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/prom/finalize
{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "prom",
    "selfLink": "/api/v1/namespaces/prom/finalize",
    "uid": "59afb211-3050-11ea-af11-005056879c91",
    "resourceVersion": "9937637",
    "creationTimestamp": "2020-01-06T06:47:04Z",
    "deletionTimestamp": "2020-02-11T04:11:57Z",
    "annotations": {
      "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"prom\"}}\n"
    }
  },
  "spec": {

  },
  "status": {
    "phase": "Terminating"
  }
}[root@master pos]#

5、查看结果

[root@master pos]# kubectl get ns
NAME              STATUS   AGE
bcia              Active   42d
data              Active   42d
default           Active   54d
ingress-nginx     Active   32d
kube-node-lease   Active   54d
kube-public       Active   54d
kube-system       Active   54d
monitoring        Active   41d
pos               Active   95m
weave             Active   35d

删除成功

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐