1. 首页
  2. 技术知识

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

目录

    json 格式导出 namespace 信息修改 json 文件开启 proxy 服务调用接口删除 namespace

以下的 tool 为 Terminating 状态的 namespace,下面相关的一些操作记得将 tool 修改成自己的 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. }

复制代码

将 spec 和 status 下面的内容清空,将 metadata 字段花括号结尾的逗号去掉,保留完整的 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. }

复制代码
开启 proxy 服务

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

  1. kubectl proxy

复制代码

开启后会返回如下的内容

  1. Starting to serve on 127.0.0.1:8001

复制代码
调用接口删除 namespace

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

    tool.json – 记得修改成自己的文件名称tool/finalize – 里面的 tool 修改成自己的 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

复制代码

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

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

原创文章,作者:starterknow,如若转载,请注明出处:https://www.starterknow.com/108228.html

联系我们