k8s namespace 一直处于 Terminating 状态的解决方法
- 以下的
tool
为Terminating
状态的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 是否还存在