当前位置: 首页 > 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.zskr.cn/news/40068.html

相关文章:

  • go语言访问新浪股票(hq.sinajs.cn)
  • 优化算法三剑客:SGD、Adam、AdamW的深度对比
  • 从零开始搭建你的 Hexo 静态博客(支持 macOS 与 Windows)
  • cmake也是个恶大的玩意
  • docker 常用命令本地部署打包
  • 用古代数论分析电磁波频谱
  • AddressSanitizer (ASan) is a fast memory error detector
  • 2025年11月轴连轴承厂家推荐榜:行业领导者徐州优力同创解决方案解析
  • 基于业务知识和代码库增强的大模型生成代码实践
  • 完整教程:软件设计师-计算机基础-CPU题型
  • 超人福袋助手,抖音福袋扭蛋机,抖音抢福袋工具
  • P12028 [USACO25OPEN] Moo Decomposition G 题解
  • Automation 错误
  • 【AI智能体】Coze 打造AI数字人视频生成智能体实战详解 - 教程
  • 基于GA-SVM的织物瑕疵种类识别算法matlab仿真,包含GUI界面 - 实践
  • 软件工程学习日志2025.11.4
  • go语言访问新浪股票
  • Hugging Face的基础使用
  • 2025上海SAT线上培训机构推荐:线上课程首选“无老师国际教育”
  • Java基础加强13-集合框架、Stream流 - 指南
  • 高级语言程序第三次作业 - 102300317
  • Scaling Law至现有AI即将跌落神坛?AI大模型的“增长神话”是否正在崩塌-上篇 - 实践
  • The 2024 ICPC Asia Nanjing Regional Contest (The 3rd Universal Cup. Stage 16: Nanjing) 题解
  • 完整教程:四大名著智能可视化推演平台
  • 2025年靠谱的气体探测器专业厂家推荐,气体探测器企业全解析
  • 2025年重庆正宗陈麻花品牌口碑排名:陈建平麻花客户评价如何、性价比怎么样、价格合理吗全解析
  • Introduction to Microsoft Visual C++/MFC
  • 收藏!计算机领域除顶会外,这6大核心期刊你绝不能错过
  • 2025年沈阳编程机构权威推荐榜单:spike编程/scratch编程/python编程源头机构精选
  • Gitlab通过Token生成的用户怎么删除