K8s删除terminating的namespace
程序员文章站
2024-03-11 16:58:13
...
K3s/k8s 删除terminating状态的Namespace
说明: 删除已经停止的 namespace 和 删除 普通的 pod 、deployment、svc等不同。不能使用 --force。具体步骤如下:
1、导出描述的json文件
kubectl get ns longhorn-system -o json > longhorn-system.json
a)打开导出的json文件 longhorn-system.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"longhorn-system\"}}\n"
},
"creationTimestamp": "2020-06-15T03:38:43Z",
"deletionTimestamp": "2020-06-15T13:50:41Z",
"managedFields": [
...........此处省略..........
],
"name": "longhorn-system",
"resourceVersion": "78488",
"selfLink": "/api/v1/namespaces/longhorn-system",
"uid": "219da01a-019b-48df-96bc-2ab227db0b40"
},
"spec": {
"finalizers": [
"kubernetes" // 删除
]
},
"status": {
"conditions": [
......此处省略.....
],
"phase": "Terminating"
}
}
b) 删除 spec 字段中的 “kubernetes”,改为
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"longhorn-system\"}}\n"
},
"creationTimestamp": "2020-06-15T03:38:43Z",
"deletionTimestamp": "2020-06-15T13:50:41Z",
"managedFields": [
...........此处省略..........
],
"name": "longhorn-system",
"resourceVersion": "78488",
"selfLink": "/api/v1/namespaces/longhorn-system",
"uid": "219da01a-019b-48df-96bc-2ab227db0b40"
},
"spec": {
"finalizers": [
]
},
"status": {
"conditions": [
......此处省略.....
],
"phase": "Terminating"
}
}
2、执行清除命令
kubectl replace --raw "/api/v1/namespaces/$[ longhorn-system ]/finalize" -f ./longhorn-system.json
其中 $[ longhorn-system ] 替换为 对应的 名称空间。比如 “/api/v1/namespaces/test-namespace/finalize”
推荐阅读
-
K8s删除terminating的namespace
-
k8s的deploy、service、namespace模板
-
kubeflow 删除用户对应的 namespace
-
Kubernetes删除一直Terminating状态的namespace
-
Kubernetes强制删除一直处于Terminating状态的pod,namespace
-
删除一直处于terminating状态的namespace
-
Kubernetes强制删除一直处于Terminating状态的pod,namespace
-
Kubernetes:强制删除一直处于Terminating状态的pod,deployment,namespace,server
-
k8s删除Terminating状态的命名空间
-
k8s删除pod一直处于terminating状态