查看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
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐