- 想删除K8S当中的一个名称空间
使用如下命令删除一直卡着,手动终止之后发现名称空间为”Terminating”状态
[root@k8s-master01 storage]# kubectl get ns -ANAME STATUS AGEdefault Active 3d6hkube-node-lease Active 3d6hkube-public Active 3d6hkube-system Active 3d6hkubesphere-alerting-system Active 4h12mkubesphere-controls-system Active 2d5hkubesphere-devops-system Active 4h12mkubesphere-logging-system Active 4h12mkubesphere-monitoring-system Active 4h55mkubesphere-system Terminating 4h12mopenpitrix-system Active 4h12m[root@k8s-master01 storage]##使用如下命令删除发现名称空间为"Terminating"[root@k8s-master01 storage]# kubectl delete ns kubesphere-alerting-systemnamespace "kubesphere-alerting-system" deleted^C[root@k8s-master01 storage]# kubectl get ns -ANAME STATUS AGEdefault Active 3d6hkube-node-lease Active 73skube-public Active 3d6hkube-system Active 3d6hkubesphere-alerting-system Terminating 4h15mkubesphere-controls-system Active 2d6hkubesphere-devops-system Active 4h15mkubesphere-logging-system Active 4h15mkubesphere-monitoring-system Active 4h58mkubesphere-system Terminating 4h15mopenpitrix-system Active 4h15m[root@k8s-master01 storage]##试一下强制删除的方法,同样是"Terminating"状态[root@k8s-master01 storage]# kubectl delete ns kubesphere-controls-system --force --grace-period=0warning: 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 "kubesphere-controls-system" force deleted^C[root@k8s-master01 storage]#[root@k8s-master01 storage]# kubectl get ns kubesphere-controls-systemNAME STATUS AGEkubesphere-controls-system Terminating 2d6h[root@k8s-master01 storage]#
- 使用如下方法
网上搜索了一下,可以使用以下方法删除
kubectl get namespace 命名空间的名字 -o json > devtesting.json#示例[root@k8s-master01 storage]# kubectl get ns kubesphere-alerting-system -o json > devtesting.json[root@k8s-master01 storage]#
编辑devtesting.json文件,删除spec和finalizers这两个字段包含的内容。
"spec": {"finalizers": ["kubernetes"]},#改为"spec": {},
使用kubectl代理,执行命名
[root@k8s-master01 storage]# kubectl proxy --port=8081Starting to serve on 127.0.0.1:8081#再开一个窗口试下能不能访问[root@k8s-master01 storage]# curl http://localhost:8081/api{"kind": "APIVersions","versions": ["v1"],"serverAddressByClientCIDRs": [{"clientCIDR": "0.0.0.0/0","serverAddress": "192.168.1.8:6443"}]}[root@k8s-master01 storage]#
使用http接口进行删除
curl -k -H "Content-Type: application/json" -X PUT --data-binary @devtesting.json http://127.0.0.1:8080/api/v1/namespaces/命名空间的名字/finalize#示例[root@k8s-master01 storage]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @devtesting.json http://127.0.0.1:8081/api/v1/namespaces/kubesphere-alerting-system/finalize{"kind": "Namespace","apiVersion": "v1","metadata": {"name": "kubesphere-alerting-system","selfLink": "/api/v1/namespaces/kubesphere-alerting-system/finalize","uid": "966d12a7-2de6-49ac-956d-811742764f41","resourceVersion": "374909","creationTimestamp": "2020-11-22T10:09:02Z","deletionTimestamp": "2020-11-22T14:22:36Z","labels": {"kubesphere.io/namespace": "kubesphere-alerting-system","kubesphere.io/workspace": "system-workspace"}},"spec": {},"status": {"phase": "Terminating","conditions": [{"type": "NamespaceDeletionDiscoveryFailure","status": "True","lastTransitionTime": "2020-11-22T14:22:41Z","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": "2020-11-22T14:22:41Z","reason": "ParsedGroupVersions","message": "All legacy kube types successfully parsed"},{"type": "NamespaceDeletionContentFailure","status": "False","lastTransitionTime": "2020-11-22T14:22:41Z","reason": "ContentDeleted","message": "All content successfully deleted"}]}}[root@k8s-master01 storage]#[root@k8s-master01 storage]# kubectl get ns kubesphere-alerting-systemError from server (NotFound): namespaces "kubesphere-alerting-system" not found[root@k8s-master01 storage]##成功删除
