k8s中namespace有两种常见的状态,即Active和Terminating状态,其中Terminating状态一般会比较少见,当对应的命名空间下还存在运行的资源,但该命名空间被删除时才会出现所谓的Terminating状态,这种情况下只要等待k8s本身将命名空间下的资源回收后,该命名空间将会被系统自动删除。
但是在某些情况下,即使命名空间下没有运行的资源,但依然无法删除Terminating状态的命名空间的情况,它会一直卡在Terminating状态下。
解决这个问题的步骤为:
$ kubectl get ns | grep rdb rdbms Terminating 6d21h $ kubectl get ns rdbms -o yaml apiVersion: v1 kind: Namespace metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"name":"rdbms"}} creationTimestamp: "2020-05-07T15:19:43Z" deletionTimestamp: "2020-05-07T15:33:23Z" name: rdbms resourceVersion: "84553454" selfLink: /api/v1/namespaces/rdbms uid: 457788ddf-53d7-4hde-afa3-1fertg21ewe1 spec: finalizers: - kubernetes status: phase: Terminating
# 查看k8s集群中可以使用命名空间隔离的资源 $ kubectl api-resources -o name --verbs=list --namespaced | xargs -n 1 kubectl get --show-kind --ignore-not-found -n rdbms
发现rdbms命名空间下并无资源占用。
$ kubectl delete ns rdbms Error from server (Conflict): Operation cannot be fulfilled on namespaces "rdbms": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.
提示删除操作未能完成,说系统会在确定没用资源后将会被自动删除。
$ kubectl delete ns rdbms --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. Error from server (Conflict): Operation cannot be fulfilled on namespaces "rdbms": The system is ensuring all content is removed from this namespace. Upon completion, this namespace will automatically be purged by the system.
依然无法删除该命名空间。
$ kubectl get ns rdbms -o json > rdbms.json
查看namespace定义的json配置,编辑json文件并删除掉spec部分。
$ cat rdbms.json { "apiVersion": "v1", "kind": "Namespace", "metadata": { "annotations": { "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"rdbms\"}}\n" }, "creationTimestamp": "2019-10-14T12:17:44Z", "deletionTimestamp": "2019-10-14T12:30:27Z", "name": "rdbms", "resourceVersion": "8844754", "selfLink": "/api/v1/namespaces/rdbms", "uid": "29067ddf-56d7-4cce-afa3-1fbdbb221ab1" }, "spec": { "finalizers": [ "kubernetes" ] }, "status": { "phase": "Terminating" } }
执行接口PUT请求更新后,命名空间将自动删除。
$ curl --cacert /root/ca.crt --cert /root/client.crt --key /root/client.key -k -H "Content-Type:application/json" -X PUT --data-binary @rdbms.json https://x.x.x.x:5443/api/v1/namespaces/rdbms/finalize { "kind": "Namespace", "apiVersion": "v1", "metadata": { "name": "rdbms", "selfLink": "/api/v1/namespaces/rdbms/finalize", "uid": "29067ddf-56d7-4cce-afa3-1fbdbb221ab1", "resourceVersion": "8844754", "creationTimestamp": "2019-10-14T12:17:44Z", "deletionTimestamp": "2019-10-14T12:30:27Z", "annotations": { "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"rdbms\"}}\n" } }, "spec": { }, "status": { "phase": "Terminating" }
说明:
登录CCE控制台,在左侧导航栏中选择“资源管理 > 集群管理”,单击待连接集群的名称,在集群基本信息中获取“内网apiserver地址”后的IP地址和端口号。
再次查看namespace发现已经被删除了
$ kubectl get ns | grep rdb
通常操作系统和软件开发包中都包含文本编辑器,可以用来编辑配置文件,文档文件...
前言 对于像作者一样已经工作的上班族来说,6月7号到9号三天无疑是兴奋到飞起的...
C ++是竞争性编程中最推荐的语言之一。因为他处理速度之快,可用的库之多等等。 ...
不同区域、不同规格的裸金属服务器价格有所差异,您可以在 产品价格详情 查询价...
客户简介 UC 浏览器(UC Browser)是 UC Mobile Limited在2004年8月开发的一款软...
【51CTO.com快译】尽管多云管理与监控领域已经非常拥挤,Oracle仍然进入了这个市...
有需要 租用服务器 的朋友可能在求购时总会遇到这样那样的问题,当发了求购需求...
包年包月是一种先付费后使用的计费方式。通过包年包月,您可以提前预留资源,同...
【51CTO.com快译】如今,人们生活和工作在越来越以数据为中心的业务环境中,而数...
中国互联网的快速发展与普及带动了相关产业链的成长,同时,电信增值业务也为互...