configuration 命名空间_k8s删除Terminating状态的命名空间

背景: 我们都知道在k8s中namespace有两种常见的状态,即Active和Terminating状态,其中后者一般会比较少见,只有当对应的命名空间下还存在运行的资源,但是该命名空间被删除时才会出现所谓的terminating状态,这种情况下只要等待k8s本身将命名空间下的资源回收后,该命名空间将会被系统自动删除。但是今天遇到命名空间下已没相关资源,但依然无法删除terminating状态的命名空间的情况,特此记录一下.

查看命名空间详情

$ kubectl  get ns  | grep rdbrdbms                  Terminating   6d21h$ kubectl  get ns rdbms -o yamlapiVersion: v1kind: Namespacemetadata:  annotations:    kubectl.kubernetes.io/last-applied-configuration: |      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"name":"rdbms"}}  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-1fbdbb221ab1spec:  finalizers:  - kubernetesstatus:  phase: Terminating

查看该命名空间下的资源

# 查看k8s集群中可以使用命名空间隔离的资源$ kubectl api-resources -o name --verbs=list --namespaced | xargs -n 1 kubectl get --show-kind --ignore-not-found -n rdbms# 发现rdbms命名空间下并无资源占用

尝试对命名空间进行删除

# 直接删除命名空间rdbms## 提示删除操作未能完成,说系统会在确定没用没用资源后将会被自动删除$ kubectl  delete ns rdbmsError 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=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.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.

使用原生接口删除

# 获取namespace的详情信息$ kubectl  get ns rdbms  -o json > rdbms.json# 查看napespace定义的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"}}"        },        "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"    }}# 使用http接口进行删除$ curl -k -H "Content-Type:application/json" -X PUT --data-binary @rdbms.json https://x.x.x.x:6443/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"}}"    }  },  "spec": {  },  "status": {    "phase": "Terminating"  }# 再次查看namespace发现已经被删除了$ kubectl  get ns  | grep rdb
bceebcf704f581253c6f18462bb2f938.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值