K8S 中强制删除namespace 命名空间后 显示 Terminating 状态

K8S 中强制删除namespace 命名空间后 显示 Terminating 状态。

并且报错 warning: Immediate deletion does not wait for confirmation that the running

 

故障现象:

[root@master-1 ~]# kubectl delete ns mysql –force –grace-period=0

warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
[root@master-1 ~]# kubectl get ns
NAME                   STATUS        AGE
default                Active        67d
efk                    Active        21h
ingress-nginx          Active        59d
kube-node-lease        Active        67d
kube-public            Active        67d
kube-system            Active        67d
kubernetes-dashboard   Active        67d
ms                     Active        40d
mysql                  Terminating   42d

 

解决方法:

[root@master-1 ~]# kubectl get ns mysql -o json > mysql.json

删除其中的spec字段,因为k8s集群是携带认证的

 

 

[root@master-1 ~]# vim mysql.json

图片[1]-K8S 中强制删除namespace 命名空间后 显示 Terminating   状态-飞翔沫沫情

删除spec字段后,执行以下curl命令,使用kube-apiserver的8080端口,执行删除操作

#注意修改@XXX.json ,修改 namespaces/XXX/finalize ,其中XXX 表示你要删除的命名空间名称

 

[root@master-1 ~]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @mysql.json http://127.0.0.1:8080/api/v1/namespaces/mysql/finalize

 

再次查看ns

NAME                   STATUS        AGE
default                Active        67d
efk                    Active        21h
ingress-nginx          Active        59d
kube-node-lease        Active        67d
kube-public            Active        67d
kube-system            Active        67d
kubernetes-dashboard   Active        67d
ms                     Active        40d

 

备注:

如果kube-apiserver未开非安全端口,可以手动创建一个代理会话

# kubectl proxy –port=8081

# curl -k -H “Content-Type: application/json” -X PUT –data-binary @test.json http://127.0.0.1:8081/api/v1/namespaces/test/finalize

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容