强制删除namespace
之前部署过一套监控
因为是本地测试环境,资源不太够,想着进行删除命名空间monitoring
[root@k8s-master01 ]# kubectl delete ns monitoring
namespace "monitoring" deleted
^C
[root@k8s-master01 ]# kubectl delete ns monitoring
namespace "monitoring" deleted
^C
[root@k8s-master01 ]# kubectl delete ns monitoring --force
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.
namespace "monitoring" force deleted
^C
一直删除不掉
解决办法
强制删除
[root@k8s-master01 ~]# kubectl get namespace monitoring -o json > monitoring.json
删除这几行
删除后
启动 运行kube-proxy
[root@k8s-master01 sonarqube]# kubectl proxy
Starting to serve on 127.0.0.1:8001
窗口不能关闭
通过API执行强制删除操作
[root@k8s-master01 ~]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @monitoring.json http://127.0.0.1:8001/api/v1/namespaces/monitoring/finalize
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "monitoring",
"uid": "37ab45a2-fbb9-4162-80f5-8e9957cd833f",
"resourceVersion": "3147665",
"creationTimestamp": "2023-03-15T14:47:22Z",
"deletionTimestamp": "2023-07-24T16:45:36Z",
"labels": {
"kubernetes.io/metadata.name": "monitoring"
}
},
"spec": {},
"status": {
"phase": "Terminating",
"conditions": [
{
"type": "NamespaceDeletionDiscoveryFailure",
"status": "True",
"lastTransitionTime": "2023-07-24T16:45:49Z",
"reason": "DiscoveryFailed",
"message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request"
},
{
"type": "NamespaceDeletionGroupVersionParsingFailure",
"status": "False",
"lastTransitionTime": "2023-07-24T16:45:43Z",
"reason": "ParsedGroupVersions",
"message": "All legacy kube types successfully parsed"
},
{
"type": "NamespaceDeletionContentFailure",
"status": "False",
"lastTransitionTime": "2023-07-24T16:45:43Z",
"reason": "ContentDeleted",
"message": "All content successfully deleted, may be waiting on finalization"
},
{
"type": "NamespaceContentRemaining",
"status": "False",
"lastTransitionTime": "2023-07-24T16:45:52Z",
"reason": "ContentRemoved",
"message": "All content successfully removed"
},
{
"type": "NamespaceFinalizersRemaining",
"status": "False",
"lastTransitionTime": "2023-07-24T16:45:43Z",
"reason": "ContentHasNoFinalizers",
"message": "All content-preserving finalizers finished"
}
]
}
}
再次删除测试
[root@k8s-master01 sonarqube]# kubectl delete ns monitoring
Error from server (NotFound): namespaces "monitoring" not found
可以看到已经进行删除
[root@k8s-master01 sonarqube]# kubectl get ns -A | grep monitoring
[root@k8s-master01 sonarqube]#