Kubernetes删除一直处于Terminating状态的namespace

问题现象:

删除namespace,一直处于Terminating,并且用--force --grace-period=0 也删除不了

develop       Terminating   4d9h

Error from server (Conflict): error when deleting "ns.yaml": Operation cannot be fulfilled on namespaces "develop": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.

解决方案:

Step1:查看namespace 是否还是Terminating

 kubectl get namespaces

Step2: 查看yaml文件 ,finalizers是 - kubernetes

 kubectl get namespace <terminating-namespace> -o yaml
复制代码
 apiVersion: v1
 kind: Namespace
 metadata:
   creationTimestamp: 2020-05-20T18:48:30Z
   deletionTimestamp: 2020-05-20T18:59:36Z
   name: develop
   resourceVersion: "1385077"
   selfLink: /api/v1/namespaces/<terminating-namespace>
   uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5
 spec:
   finalizers:
   - kubernetes
 status:
   phase: Terminating
复制代码

Step3:获取namespace的json文件

 kubectl get namespace <terminating-namespace> -o json >tmp.json
复制代码
 {
      "apiVersion": "v1",
      "kind": "Namespace",
      "metadata": {
          "creationTimestamp": "2020-05-20T18:48:30Z",
          "deletionTimestamp": "2020-05-20T18:59:36Z",
          "name": "<terminating-namespace>",
          "resourceVersion": "1385077",
          "selfLink": "/api/v1/namespaces/<terminating-namespace>",
          "uid": "b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5"
      },
      "spec": {
         "finalizers": 
      },
      "status": {
          "phase": "Terminating"
      }
  }
复制代码

Step4:修改json文件,将finalizers去掉

复制代码
{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "annotations": {
            "scheduler.alpha.kubernetes.io/node-selector": "scen=kuai-develop,user=kuai-all"
        },
        "creationTimestamp": "2020-05-20T05:30:21Z",
        "deletionTimestamp": "2020-05-20T04:22:14Z",
        "name": "develop",
        "resourceVersion": "388130567",
        "selfLink": "/api/v1/namespaces/kuai-develop",
        "uid": "2b967bf4-966d-11ea-885f-246e967d5d94"
    },
    "spec": {
    },
    "status": {
        "phase": "Terminating"
    }
}
复制代码

Step5:执行命令

curl -k -H "Authorization: Bearer ${token}" -H "Content-Type: application/json" -X PUT --data-binary @tmp.json https://10.196.0.1:443/api/v1/namespaces/${namespace}/finalize

 

参考:https://www.ibm.com/support/knowledgecenter/en/SSBS6K_3.1.1/troubleshoot/ns_terminating.html

posted @   sixinshuier  阅读(416)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示