【问题解决】k8s删除namespace一直处于Terminating

清理高可用安装的rancher时,遇到namespace无法delete删除,一直处于Terminating的状态。所以就寻找了各种方法解决。

现整理如下:

方法一:

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
kubectl delete namespace local --grace-period=0 --force
 
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
 

方法二:

直接编辑namespace配置:
kubectl edit ns prom

删除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"
    },
    "spec": {
        "finalizers": [
            "kubernetes"
        ]
    },
    "status": {
        "phase": "Terminating"
    }
}

修改后为

{
    "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和status内容

[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"
    }
}

启动代理

[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

调用接口

[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]#

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值