当前位置 博文首页 > 文章内容

    k8s删除Terminating状态的命名空间

    作者: 栏目:未分类 时间:2020-07-09 11:04:17

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    一、概述

    最近部署kubesphere时,使用kubectl  delete -f xxx.yaml,再次执行 kubectl apply -f xxx.yaml,提示:

    Error from server (Forbidden): error when creating "kubesphere-complete-setup.yaml": configmaps "ks-installer" is forbidden: unable to create new content in namespace kubesphere-system because it is being terminated
    Error from server (Forbidden): error when creating "kubesphere-complete-setup.yaml": serviceaccounts "ks-installer" is forbidden: unable to create new content in namespace kubesphere-system because it is being terminated
    Error from server (Forbidden): error when creating "kubesphere-complete-setup.yaml": deployments.apps "ks-installer" is forbidden: unable to create new content in namespace kubesphere-system because it is being terminated

     

    查看命名空间

    # kubectl  get ns 
    NAME                STATUS        AGE
    default             Active        15h
    kube-node-lease     Active        15h
    kube-public         Active        15h
    kube-system         Active        15h
    kubesphere-system   Terminating   28m

    发现kubesphere-system一直处于Terminating 状态。无法删除命名空间!!

     

    二、解决方法

    查看kubesphere-system的namespace描述

    kubectl get ns kubesphere-system  -o json > kubesphere-system.json

     

    编辑json文件,删除spec字段的内存,因为k8s集群时需要认证的。

    vi kubesphere-system.json

    "spec": {
            "finalizers": [
                "kubernetes"
            ]
        },

    更改为:

    "spec": {
        
      },

     

    新开一个窗口运行kubectl proxy跑一个API代理在本地的8081端口

    # kubectl proxy --port=8081
    Starting to serve on 127.0.0.1:8081

     

    最后运行curl命令进行删除

    curl -k -H "Content-Type:application/json" -X PUT --data-binary @kubesphere-system.json http://127.0.0.1:8081/api/v1/namespaces/kubesphere-system/finalize

    输出:

    {
      "kind": "Namespace",
      "apiVersion": "v1",
      "metadata": {
        "name": "kubesphere-system",
        "selfLink": "/api/v1/namespaces/kubesphere-system/finalize",
        "uid": "ba8b8bcd-adf0-4f4f-b6bf-ebab51c00252",
        "resourceVersion": "72676",
        "creationTimestamp": "2020-07-09T02:04:37Z",
        "deletionTimestamp": "2020-07-09T02:09:41Z",
        "annotations": {
          "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"kubesphere-system\"}}\n"
        }
      },
      "spec": {
        
      },
      "status": {
        "phase": "Terminating",
        "conditions": [
          {
            "type": "NamespaceDeletionDiscoveryFailure",
            "status": "True",
            "lastTransitionTime": "2020-07-09T02:09:46Z",
            "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-07-09T02:09:47Z",
            "reason": "ParsedGroupVersions",
            "message": "All legacy kube types successfully parsed"
          },
          {
            "type": "NamespaceDeletionContentFailure",
            "status": "False",
            "lastTransitionTime": "2020-07-09T02:09:47Z",
            "reason": "ContentDeleted",
            "message": "All content successfully deleted"
          }
        ]
      }
    }
    View Code

     

    再次查看命名空间

    # kubectl get ns
    NAME              STATUS   AGE
    default           Active   15h
    kube-node-lease   Active   15h
    kube-public       Active   15h
    kube-system       Active   15h

    发现kubesphere-system命名空间已经消失了。

     

    最后再次执行 kubectl apply -f xxx.yaml,就正常了。

     

     

    本文参考链接:

    https://blog.csdn.net/tongzidane/article/details/88988542