当前位置: 代码网 > 服务器>服务器>云虚拟主机 > 解决k8s namespace 一直处于 Terminating 状态的问题

解决k8s namespace 一直处于 Terminating 状态的问题

2024年06月02日 云虚拟主机 我要评论
以下的 tool 为 terminating 状态的 namespace,下面相关的一些操作记得将 tool 修改成自己的 namespace 名称json 格式导出 namespace 信息k ge

以下的 toolterminating 状态的 namespace,下面相关的一些操作记得将 tool 修改成自己的 namespace 名称

json 格式导出 namespace 信息

k get ns tool -o json > tool.json

修改 json 文件

{
    "apiversion": "v1",
    "kind": "namespace",
    "metadata": {
        "annotations": {
            "applicationcnname": "tool",
            "kubernetes.customized/bocloud_env_id": "3",
            "kubernetes.customized/bocloud_partition_id": "172",
            "kubernetes.customized/project_creator": "7",
            "kubernetes.customized/project_id": "10",
            "kubernetes.customized/tree_application_id": "10"
        },
        "creationtimestamp": "2022-10-18t06:38:25z",
        "deletiontimestamp": "2022-10-20t02:34:18z",
        "labels": {
            "app": "tool"
        },
        "name": "tool",
        "resourceversion": "1011030",
        "selflink": "/api/v1/namespaces/tool",
        "uid": "79793f2c-5290-4225-938b-8ce9e639a38c"
    },
    "spec": {
        "finalizers": [
            "kubernetes"
        ]
    },
    "status": {
        "conditions": [
            {
                "lasttransitiontime": "2022-10-20t02:34:23z",
                "message": "discovery failed for some groups, 2 failing: unable to retrieve the complete list of server apis: custom.metrics.k8s.io/v1beta1: the server is currently unable to handle the request, metrics.k8s.io/v1beta1: the server is currently unable to handle the request",
                "reason": "discoveryfailed",
                "status": "true",
                "type": "namespacedeletiondiscoveryfailure"
            },
            {
                "lasttransitiontime": "2022-10-20t02:34:23z",
                "message": "all legacy kube types successfully parsed",
                "reason": "parsedgroupversions",
                "status": "false",
                "type": "namespacedeletiongroupversionparsingfailure"
            },
            {
                "lasttransitiontime": "2022-10-20t02:34:23z",
                "message": "all content successfully deleted, may be waiting on finalization",
                "reason": "contentdeleted",
                "status": "false",
                "type": "namespacedeletioncontentfailure"
            },
            {
                "lasttransitiontime": "2022-10-20t02:34:23z",
                "message": "all content successfully removed",
                "reason": "contentremoved",
                "status": "false",
                "type": "namespacecontentremaining"
            },
            {
                "lasttransitiontime": "2022-10-20t02:34:23z",
                "message": "all content-preserving finalizers finished",
                "reason": "contenthasnofinalizers",
                "status": "false",
                "type": "namespacefinalizersremaining"
            }
        ],
        "phase": "terminating"
    }
}

将 spec 和 status 下面的内容清空,将 metadata 字段花括号结尾的逗号去掉,保留完整的 json 格式

以下是修改过后的样式 [ 提供参考的,用来和原始 json 做对比,好增加理解 ]

{
    "apiversion": "v1",
    "kind": "namespace",
    "metadata": {
        "annotations": {
            "applicationcnname": "tool",
            "kubernetes.customized/bocloud_env_id": "3",
            "kubernetes.customized/bocloud_partition_id": "172",
            "kubernetes.customized/project_creator": "7",
            "kubernetes.customized/project_id": "10",
            "kubernetes.customized/tree_application_id": "10"
        },
        "creationtimestamp": "2022-10-18t06:38:25z",
        "deletiontimestamp": "2022-10-20t02:34:18z",
        "labels": {
            "app": "tool"
        },
        "name": "tool",
        "resourceversion": "1011030",
        "selflink": "/api/v1/namespaces/tool",
        "uid": "79793f2c-5290-4225-938b-8ce9e639a38c"
    }
}

开启 proxy 服务

这个时候要新打开一个终端,开启的 proxy 服务不是后台运行的,会占用一个终端

kubectl proxy

开启后会返回如下的内容

starting to serve on 127.0.0.1:8001

调用接口删除 namespace

在另一个可以操作命令的终端,执行下面的 curl 命令

  • tool.json - 记得修改成自己的文件名称
  • tool/finalize - 里面的 tool 修改成自己的 namespace 名称
curl -k -h "content-type: application/json" \
-x put --data-binary @tool.json \
http://127.0.0.1:8001/api/v1/namespaces/tool/finalize

通过 kubectl 命令查看 namespace 是否还存在

到此这篇关于k8s namespace 一直处于 terminating 状态的解决方法的文章就介绍到这了,更多相关k8s 命名空间处于 terminating 状态内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com