删除 k8s 中状态一直为 Terminating 的 namespace

查看ns或者namespace

[root@master1 ~]# kubectl get ns 
NAME              STATUS        AGE
default           Active        5d1h
elastic-system    Active        4h49m
kube-logging      Active        4d22h
kube-node-lease   Active        5d1h
kube-public       Active        5d1h
kube-system       Active        5d1h
rook-ceph         Terminating   4d23h

其中有个状态是 Terminating 的 ns,强制删除这个 ns 不管用。

解决:

1、查看这个 ns 中的 finalizer

[root@master1 ~]# kubectl get namespace rook-ceph -o yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"name":"rook-ceph"}}
  creationTimestamp: "2021-10-09T08:41:52Z"
  deletionTimestamp: "2021-10-14T06:43:50Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
      f:status:
        f:phase: {}
    manager: kubectl-client-side-apply
    operation: Update
    time: "2021-10-09T08:41:52Z"
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:conditions:
          .: {}
          k:{"type":"NamespaceContentRemaining"}:
            .: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{"type":"NamespaceDeletionContentFailure"}:
            .: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{"type":"NamespaceDeletionDiscoveryFailure"}:
            .: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{"type":"NamespaceDeletionGroupVersionParsingFailure"}:
            .: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{"type":"NamespaceFinalizersRemaining"}:
            .: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
    manager: kube-controller-manager
    operation: Update
    time: "2021-10-14T06:44:34Z"
  name: rook-ceph
  resourceVersion: "2217801"
  selfLink: /api/v1/namespaces/rook-ceph
  uid: e585eebc-6564-437e-8f00-f959c6d6918a
spec:
  finalizers:                 # 查看这个字段值
  - kubernetes
status:
  conditions:
  - lastTransitionTime: "2021-10-14T06:44:04Z"
    message: All resources successfully discovered
    reason: ResourcesDiscovered
    status: "False"
    type: NamespaceDeletionDiscoveryFailure
  - lastTransitionTime: "2021-10-14T06:44:04Z"
    message: All legacy kube types successfully parsed
    reason: ParsedGroupVersions
    status: "False"
    type: NamespaceDeletionGroupVersionParsingFailure
  - lastTransitionTime: "2021-10-14T06:44:34Z"
    message: All content successfully deleted, may be waiting on finalization
    reason: ContentDeleted
    status: "False"
    type: NamespaceDeletionContentFailure
  - lastTransitionTime: "2021-10-14T06:44:04Z"
    message: 'Some resources are remaining: cephclusters.ceph.rook.io has 1 resource
      instances'
    reason: SomeResourcesRemain
    status: "True"
    type: NamespaceContentRemaining
  - lastTransitionTime: "2021-10-14T06:44:04Z"
    message: 'Some content in the namespace has finalizers remaining: cephcluster.ceph.rook.io
      in 1 resource instances'
    reason: SomeFinalizersRemain
    status: "True"
    type: NamespaceFinalizersRemaining
  phase: Terminating

2、导出这个json文件

kubectl get namespace rook-ceph -o json >tmp.json

3、编辑这个 json 文件,删除 finalizers 字段的值

manager: kube-controller-manager
    operation: Update
    time: "2021-10-14T06:44:34Z"
  name: rook-ceph
  resourceVersion: "2217801"
  selfLink: /api/v1/namespaces/rook-ceph
  uid: e585eebc-6564-437e-8f00-f959c6d6918a
spec:
  finalizers:
  - kubernetes                        # 删除这个值
status:
  conditions:
  - lastTransitionTime: "2021-10-14T06:44:04Z"
    message: All resources successfully discovered
    reason: ResourcesDiscovered
    status: "False"

4、开启 proxy (开启 proxy 后不要动)

kubectl proxy

5、重新打开另一个命令行执行以下命令 (以下命令中 terminating-namespace 改成自己要删除的 namespace)

curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize

6、再查看 ns

[root@master1 ~]# kubectl get ns
NAME              STATUS   AGE
default           Active   5d1h
elastic-system    Active   4h57m
kube-logging      Active   4d22h
kube-node-lease   Active   5d1h
kube-public       Active   5d1h
kube-system       Active   5d1h
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值