一种删除 KubeSphere 中一直卡在 Terminating 的 Namespace--KubeSphere Logging System的简单方法

2023-12-28 00:01:36

一、问题提出

在使用 KubeSphere 的时候发现有一个日志服务KubeSphere Logging System,它被创建命名空间为kubesphere-logging-system下。当我们不想使用它,需要删除它时,确一直在 Terminating中,怎么也删除不掉。

kubectl delete ns kubesphere-logging-system  --force --grace-period=0

在这里插入图片描述

二、删除方法

1,获取kubesphere-logging-syste的详细信息json文件

首先 通过以下命令获取 namespace 的详情信息并转为 json。

kubectl get namespace kubesphere-logging-system -o json > kubesphere-logging-system.json

在这里插入图片描述

2,编辑kubesphere-logging-system.json

vim kubesphere-logging-system.json
{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "creationTimestamp": "2023-12-24T23:13:34Z",
        "deletionTimestamp": "2023-12-27T07:49:27Z",
        "labels": {
            "kubesphere.io/namespace": "kubesphere-logging-system",
            "kubesphere.io/workspace": "system-workspace"
        },
        "name": "kubesphere-logging-system",
        "resourceVersion": "2878899",
        "selfLink": "/api/v1/namespaces/kubesphere-logging-system",
        "uid": "dd01ee56-2dee-40ba-b63e-5fc71e27507b"
    },
    "spec": {
        "finalizers": [
           "kubernetes" # 将此行删除
        ]
    },
    "status": {
        "conditions": [
            {
                "lastTransitionTime": "2023-12-27T07:49:35Z",
                "message": "All resources successfully discovered",
                "reason": "ResourcesDiscovered",
                "status": "False",
                "type": "NamespaceDeletionDiscoveryFailure"
            },
            {
                "lastTransitionTime": "2023-12-27T07:49:35Z",
                "message": "All legacy kube types successfully parsed",
                "reason": "ParsedGroupVersions",
                "status": "False",
                "type": "NamespaceDeletionGroupVersionParsingFailure"
            },
            {
                "lastTransitionTime": "2023-12-27T08:47:05Z",
                "message": "All content successfully deleted, may be waiting on finalization",
                "reason": "ContentDeleted",
                "status": "False",
                "type": "NamespaceDeletionContentFailure"
            },
            {
                "lastTransitionTime": "2023-12-27T07:49:35Z",
                "message": "Some resources are remaining: exporters.events.kubesphere.io has 1 resource instances, fluentbits.logging.kubesphere.io has 1 resource instances, rulers.events.kubesphere.io has 1 resource instances",
                "reason": "SomeResourcesRemain",
                "status": "True",
                "type": "NamespaceContentRemaining"
            },
            {
                "lastTransitionTime": "2023-12-27T07:49:35Z",
                "message": "Some content in the namespace has finalizers remaining: exporters.finalizer.events.kubesphere.io in 1 resource instances, fluentbit.logging.kubesphere.io in 1 resource instances, rulers.finalizer.events.kubesphere.io in 1 resource instances",
                "reason": "SomeFinalizersRemain",
                "status": "True",
                "type": "NamespaceFinalizersRemaining"
            }
        ],
        "phase": "Terminating"
    }
}

找到 spec 将 finalizers 下的 kubernetes 删除。

3,执行清理命令

现在我们只需要一条命令 就可以彻底删除这个 Namespace。

kubectl replace --raw "/api/v1/namespaces/kubesphere-logging-system/finalize" -f ./kubesphere-logging-system.json

在这里插入图片描述

三、检查结果

查看namespace kubesphere-logging-system,

kubectl get ns kubesphere-logging-system

已经找不到命名空间kubesphere-logging-system了。
在这里插入图片描述

查看所有命名空间:

kubectl get ns

在这里插入图片描述
再次查看的时候,它已经不存在了!!

文章来源:https://blog.csdn.net/weixin_43025151/article/details/135250875
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。