当前位置: 首页 > news >正文

k8s删除Terminating状态的命名空间

k8s删除Terminating状态的命名空间
原创
于 2021-04-07 16:14:02 发布

CC 4.0 BY-SA版权

K8S/Kubernetes
文章已被社区收录
加入社区

K8S
专栏收录该内容
5 篇文章
订阅专栏
在部署Kubesphere时遇到命名空间kubesphere-system处于Terminating状态,导致无法删除。通过查看命名空间详情,编辑JSON文件移除finalizers字段,然后使用kubectl proxy创建API代理,通过curl命令强制删除命名空间,最终成功解决问题并能重新执行kubectl apply命令。
一、概述
最近部署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"
}
]
}
}
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,就正常了.
————————————————
版权声明:本文为CSDN博主「puppycuty」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_38125626/article/details/115488453

http://www.jsqmd.com/news/31486/

相关文章:

  • 【实用脚本】一键安装Oracle19c数据库
  • 程序员必逛的9个开发者社区推荐
  • CleanMyMac X 4.14.2 dmg 安装教程|Mac 清理软件详细安装步骤
  • java-迭代器
  • 优化算法三剑客:SGD、Adam、AdamW的深度对比
  • 某大厂跳动面试:计算机网络相关问题解析与总结 - 教程
  • 动手动脑5
  • AI元人文:悟空机制与反思——论智能文明的自我超越之道
  • 从零开始搭建你的 Hexo 静态博客(支持 macOS 与 Windows)
  • cmake也是个恶大的玩意
  • 实用指南:Python 运算符与列表(list)
  • 接口请求测试题目
  • iOS - 从 @property 开始
  • ESP32 中断
  • 25.11.4随笔联考总结
  • docker 常用命令本地部署打包
  • Linux中读写自旋锁rwlock的实现 - 详解
  • 用古代数论分析电磁波频谱
  • AddressSanitizer (ASan) is a fast memory error detector
  • 「CF1210F2-Marek and Matching (hard version)」题解
  • 详细介绍:【数据结构】考研算法精讲:分块查找的深度剖析 | 从“块内无序、块间有序”思想到ASL性能最优解
  • 通过发射高能电子束来控制宇宙射线
  • ICPC2025西安 游记(VP)
  • 2025年11月汽车水泵轴承源头厂家综合评测与选择指南:徐州优力同创领跑行业
  • 各种物质的在宇宙空间中的无线电频谱分析
  • PQ v.Next 团队项目Alpha阶段分工
  • Rari黑客事件全额赔偿方案详解
  • 2025年11月圆锥滚子轴承厂家权威排行:顶尖制造商徐州优力同创服务指南
  • TOON 格式终于赢了!AI 大模型基准测试揭示惊人真相
  • 2025年11月圆锥滚子轴承厂家榜单:行业领袖深度解析与采购指南