翼度科技»论坛 云主机 服务器技术 查看内容

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

6

主题

6

帖子

18

积分

新手上路

Rank: 1

积分
18
以下的
  1. tool
复制代码
  1. Terminating
复制代码
状态的
  1. namespace
复制代码
,下面相关的一些操作记得将
  1. tool
复制代码
修改成自己的
  1. namespace
复制代码
名称

json 格式导出 namespace 信息
  1. k get ns tool -o json > tool.json
复制代码
修改 json 文件
  1. {
  2.     "apiVersion": "v1",
  3.     "kind": "Namespace",
  4.     "metadata": {
  5.         "annotations": {
  6.             "applicationCnName": "tool",
  7.             "kubernetes.customized/bocloud_env_id": "3",
  8.             "kubernetes.customized/bocloud_partition_id": "172",
  9.             "kubernetes.customized/project_creator": "7",
  10.             "kubernetes.customized/project_id": "10",
  11.             "kubernetes.customized/tree_application_id": "10"
  12.         },
  13.         "creationTimestamp": "2022-10-18T06:38:25Z",
  14.         "deletionTimestamp": "2022-10-20T02:34:18Z",
  15.         "labels": {
  16.             "app": "tool"
  17.         },
  18.         "name": "tool",
  19.         "resourceVersion": "1011030",
  20.         "selfLink": "/api/v1/namespaces/tool",
  21.         "uid": "79793f2c-5290-4225-938b-8ce9e639a38c"
  22.     },
  23.     "spec": {
  24.         "finalizers": [
  25.             "kubernetes"
  26.         ]
  27.     },
  28.     "status": {
  29.         "conditions": [
  30.             {
  31.                 "lastTransitionTime": "2022-10-20T02:34:23Z",
  32.                 "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",
  33.                 "reason": "DiscoveryFailed",
  34.                 "status": "True",
  35.                 "type": "NamespaceDeletionDiscoveryFailure"
  36.             },
  37.             {
  38.                 "lastTransitionTime": "2022-10-20T02:34:23Z",
  39.                 "message": "All legacy kube types successfully parsed",
  40.                 "reason": "ParsedGroupVersions",
  41.                 "status": "False",
  42.                 "type": "NamespaceDeletionGroupVersionParsingFailure"
  43.             },
  44.             {
  45.                 "lastTransitionTime": "2022-10-20T02:34:23Z",
  46.                 "message": "All content successfully deleted, may be waiting on finalization",
  47.                 "reason": "ContentDeleted",
  48.                 "status": "False",
  49.                 "type": "NamespaceDeletionContentFailure"
  50.             },
  51.             {
  52.                 "lastTransitionTime": "2022-10-20T02:34:23Z",
  53.                 "message": "All content successfully removed",
  54.                 "reason": "ContentRemoved",
  55.                 "status": "False",
  56.                 "type": "NamespaceContentRemaining"
  57.             },
  58.             {
  59.                 "lastTransitionTime": "2022-10-20T02:34:23Z",
  60.                 "message": "All content-preserving finalizers finished",
  61.                 "reason": "ContentHasNoFinalizers",
  62.                 "status": "False",
  63.                 "type": "NamespaceFinalizersRemaining"
  64.             }
  65.         ],
  66.         "phase": "Terminating"
  67.     }
  68. }
复制代码
  1. 将 spec 和 status 下面的内容清空,将 metadata 字段花括号结尾的逗号去掉,保留完整的 json 格式
  2. 以下是修改过后的样式 [ 提供参考的,用来和原始 json 做对比,好增加理解 ]
复制代码
  1. {
  2.     "apiVersion": "v1",
  3.     "kind": "Namespace",
  4.     "metadata": {
  5.         "annotations": {
  6.             "applicationCnName": "tool",
  7.             "kubernetes.customized/bocloud_env_id": "3",
  8.             "kubernetes.customized/bocloud_partition_id": "172",
  9.             "kubernetes.customized/project_creator": "7",
  10.             "kubernetes.customized/project_id": "10",
  11.             "kubernetes.customized/tree_application_id": "10"
  12.         },
  13.         "creationTimestamp": "2022-10-18T06:38:25Z",
  14.         "deletionTimestamp": "2022-10-20T02:34:18Z",
  15.         "labels": {
  16.             "app": "tool"
  17.         },
  18.         "name": "tool",
  19.         "resourceVersion": "1011030",
  20.         "selfLink": "/api/v1/namespaces/tool",
  21.         "uid": "79793f2c-5290-4225-938b-8ce9e639a38c"
  22.     }
  23. }
复制代码
开启 proxy 服务
  1. 这个时候要新打开一个终端,开启的 proxy 服务不是后台运行的,会占用一个终端
复制代码
  1. kubectl proxy
复制代码
  1. 开启后会返回如下的内容
复制代码
  1. Starting to serve on 127.0.0.1:8001
复制代码
调用接口删除 namespace
  1. 在另一个可以操作命令的终端,执行下面的 curl 命令
复制代码

    1. tool.json
    复制代码
    - 记得修改成自己的文件名称
    1. tool/finalize
    复制代码
    - 里面的 tool 修改成自己的
    1. namespace
    复制代码
    名称
  1. curl -k -H "Content-Type: application/json" \
  2. -X PUT --data-binary @tool.json \
  3. http://127.0.0.1:8001/api/v1/namespaces/tool/finalize
复制代码
  1. 通过 kubectl 命令查看 namespace 是否还存在
复制代码
到此这篇关于k8s namespace 一直处于 Terminating 状态的解决方法的文章就介绍到这了,更多相关k8s 命名空间处于 Terminating 状态内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

来源:https://www.jb51.net/article/265963.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具