前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >k8s删除Terminating状态的命名空间

k8s删除Terminating状态的命名空间

作者头像
py3study
发布2020-08-13 10:59:48
2.9K0
发布2020-08-13 10:59:48
举报
文章被收录于专栏:python3python3python3

一、概述

最近部署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

注意:命令中的kubesphere-system就是命名空间。

输出:

{
  "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"
      }
    ]
  }
}

再次查看命名空间

# 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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-08-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、概述
  • 二、解决方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档