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

k8s中namespace有两种常见的状态,即Active和Terminating状态,其中Terminating状态一般会比较少见,当对应的命名空间下还存在运行的资源,但该命名空间被删除时才会出现所谓的Terminating状态,这种情况下只要等待k8s本身将命名空间下的资源回收后,该命名空间将会被系统自动删除。

但是在某些情况下,即使命名空间下没有运行的资源,但依然无法删除Terminating状态的命名空间的情况,它会一直卡在Terminating状态下,即使用--force --grace-period=0 也删除不了。

接下来的步骤将描述如何手动删除卡住的命名空间:

  1. Run the following command to view the namespaces that are stuck in the Terminating state:

    1
    kubectl get namespaces
  2. Select a terminating namespace and view the contents of the namespace to find out the finalizer. Run the following command:

    1
    kubectl get namespace <terminating-namespace> -o yaml

    Your YAML contents might resemble the following output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    apiVersion: v1
    kind: Namespace
    metadata:
      creationTimestamp: 2018-11-19T18:48:30Z
      deletionTimestamp: 2018-11-19T18:59:36Z
      name: <terminating-namespace>
      resourceVersion: "1385077"
      selfLink: /api/v1/namespaces/<terminating-namespace>
      uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5
    spec:
      finalizers:
      - kubernetes
    status:
      phase: Terminating
  3. Run the following command to create a temporary JSON file:

    1
    kubectl get namespace <terminating-namespace> -o json >tmp.json
  4. Edit your tmp.json file. Remove the kubernetes value from the finalizers field and save the file.

    Your tmp.json file might resemble the following output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    {
         "apiVersion": "v1",
         "kind": "Namespace",
         "metadata": {
             "creationTimestamp": "2018-11-19T18:48:30Z",
             "deletionTimestamp": "2018-11-19T18:59:36Z",
             "name": "<terminating-namespace>",
             "resourceVersion": "1385077",
             "selfLink": "/api/v1/namespaces/<terminating-namespace>",
             "uid": "b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5"
         },
         "spec": {
            "finalizers":
         },
         "status": {
             "phase": "Terminating"
         }
     }
  5. To set a temporary proxy IP and port, run the following command. Be sure to keep your terminal window open until you delete the stuck namespace:

    1
    kubectl proxy

    Your proxy IP and port might resemble the following output:

     Starting to serve on 127.0.0.1:8001
    
  6. From a new terminal window, make an API call with your temporary proxy IP and port:

    1
    curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize

    Your output might resemble the following content:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    {
       "kind": "Namespace",
       "apiVersion": "v1",
       "metadata": {
         "name": "<terminating-namespace>",
         "selfLink": "/api/v1/namespaces/<terminating-namespace>/finalize",
         "uid": "b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5",
         "resourceVersion": "1602981",
         "creationTimestamp": "2018-11-19T18:48:30Z",
         "deletionTimestamp": "2018-11-19T18:59:36Z"
       },
       "spec": {
     
       },
       "status": {
         "phase": "Terminating"
       }
    }

    Note: The finalizer parameter is removed.

  7. Verify that the terminating namespace is removed, run the following command:

    1
    kubectl get namespaces

Continue to follow the steps for other namespaces that are stuck in the Terminating state.

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

参考:https://support.huaweicloud.com/cce_faq/cce_faq_00277.html

posted @   人艰不拆_zmc  阅读(565)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2018-11-16 (转)面试必备技能:JDK动态代理给Spring事务埋下的坑!
2016-11-16 CentOS修改mysql 用户root的密码并允许远程登录
点击右上角即可分享
微信分享提示