编辑命名空间 删除finalizers字段
kubectl get namespace kubesphere-system -o json \
| tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
| kubectl replace --raw /api/v1/namespaces/kubesphere-system/finalize -f -
[root@uat-cce-40364 ~]# kubectl get ns
NAME STATUS AGE
api-gateway-test Active 23h
default Active 3d6h
kube-node-lease Active 3d6h
kube-public Active 3d6h
kube-system Active 3d6h
kubesphere-controls-system Terminating 2d1h
kubesphere-devops-system Terminating 36h
kubesphere-logging-system Terminating 9h
kubesphere-monitoring-federated Terminating 2d1h
[root@uat-cce-40364 ~]# kubectl edit namespace kubesphere-monitoring-federated
namespace/kubesphere-monitoring-federated edited
[root@uat-cce-40364 ~]# kubectl edit namespace kubesphere-logging-system
namespace/kubesphere-logging-system edited
[root@uat-cce-40364 ~]# kubectl edit namespace kubesphere-devops-system
namespace/kubesphere-devops-system edited
You have new mail in /var/spool/mail/root
[root@uat-cce-40364 ~]# kubectl get ns
NAME STATUS AGE
api-gateway-test Active 23h
default Active 3d6h
kube-node-lease Active 3d6h
kube-public Active 3d6h
kube-system Active 3d6h
kubesphere-controls-system Terminating 2d1h
kubesphere-logging-system Terminating 9h
[root@uat-cce-40364 ~]#
还是无法删除
[root@uat-cce-40364 ~]# kubectl get ns
NAME STATUS AGE
api-gateway-test Active 23h
default Active 3d6h
kube-node-lease Active 3d6h
kube-public Active 3d6h
kube-system Active 3d6h
kubesphere-logging-system Terminating 9h
[root@uat-cce-40364 ~]# kubectl delete namespace kubesphere-logging-system --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.
namespace "kubesphere-logging-system" force deleted
[root@uat-cce-40364 ~]# kubectl api-resources --namespaced=true -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n kubesphere-logging-system
Error from server (MethodNotAllowed): the server does not allow this method on the requested resource
Error from server (MethodNotAllowed): the server does not allow this method on the requested resource
NAME AGE
exporter.events.kubesphere.io/ks-events-exporter 4h56m
NAME AGE
ruler.events.kubesphere.io/ks-events-ruler 4h56m
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
NAME AGE
fluentbit.logging.kubesphere.io/fluent-bit 4h58m
[root@uat-cce-40364 ~]# kubectl -n kubesphere-logging-system delete exporters.events.kubesphere.io ks-events-exporter
exporter.events.kubesphere.io "ks-events-exporter" deleted
^C
[root@uat-cce-40364 ~]# kubectl -n kubesphere-logging-system edit exporters.events.kubesphere.io ks-events-exporter
exporter.events.kubesphere.io/ks-events-exporter edited
[root@uat-cce-40364 ~]# kubectl -n kubesphere-logging-system edit rulers.events.kubesphere.io ks-events-ruler
ruler.events.kubesphere.io/ks-events-ruler edited
[root@uat-cce-40364 ~]# kubectl -n kubesphere-logging-system edit fluentbit
fluentbitconfigs.logging.kubesphere.io fluentbits.logging.kubesphere.io
[root@uat-cce-40364 ~]# kubectl -n kubesphere-logging-system edit fluentbits.logging.kubesphere.io fluent-bit
fluentbit.logging.kubesphere.io/fluent-bit edited
[root@uat-cce-40364 ~]# kubectl api-resources --namespaced=true -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n kubesphere-logging-system
Error from server (MethodNotAllowed): the server does not allow this method on the requested resource
Error from server (MethodNotAllowed): the server does not allow this method on the requested resource
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
[root@uat-cce-40364 ~]# kubectl get ns
NAME STATUS AGE
api-gateway-test Active 23h
default Active 3d6h
kube-node-lease Active 3d6h
kube-public Active 3d6h
kube-system Active 3d6h
[root@uat-cce-40364 ~]#
https://blog.csdn.net/w2909526/article/details/117002490
[root@cce-uat-node03 ~]# kubectl -n api-precqljm get secrets
NAME TYPE DATA AGE
api-sonar-token credential.devops.kubesphere.io/basic-auth 2 46h
gateway-kubeconfig credential.devops.kubesphere.io/kubeconfig 1 46h
gitlab-token credential.devops.kubesphere.io/basic-auth 3 46h
harbor-token credential.devops.kubesphere.io/basic-auth 3 46h
[root@cce-uat-node03 ~]# kubectl get ns api-precqljm
NAME STATUS AGE
api-precqljm Terminating 46h
[root@cce-uat-node03 ~]# kubectl -n api-precqljm delete secrets api-sonar-token --grace-period=0 --force --wait=false
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.
secret "api-sonar-token" force deleted
[root@cce-uat-node03 ~]# kubectl -n api-precqljm delete secrets gateway-kubeconfig --grace-period=0 --force --wait=false
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.
secret "gateway-kubeconfig" force deleted
[root@cce-uat-node03 ~]# kubectl -n api-precqljm delete secrets gitlab-token --grace-period=0 --force --wait=false
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.
secret "gitlab-token" force deleted
[root@cce-uat-node03 ~]# kubectl -n api-precqljm delete secrets harbor-token --grace-period=0 --force --wait=false
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.
secret "harbor-token" force deleted
[root@cce-uat-node03 ~]#
[root@cce-uat-node03 ~]# kubectl -n api-precqljm patch secrets api-sonar-token -p '{"metadata":{"finalizers":null}}'
secret/api-sonar-token patched
[root@cce-uat-node03 ~]# kubectl -n api-precqljm get secrets
NAME TYPE DATA AGE
gateway-kubeconfig credential.devops.kubesphere.io/kubeconfig 1 46h
gitlab-token credential.devops.kubesphere.io/basic-auth 3 46h
harbor-token credential.devops.kubesphere.io/basic-auth 3 46h
[root@cce-uat-node03 ~]# kubectl -n api-precqljm patch secrets gateway-kubeconfig -p '{"metadata":{"finalizers":null}}'
secret/gateway-kubeconfig patched
[root@cce-uat-node03 ~]# kubectl -n api-precqljm patch secrets gitlab-token -p '{"metadata":{"finalizers":null}}'
secret/gitlab-token patched
[root@cce-uat-node03 ~]# kubectl -n api-precqljm patch secrets harbor-token -p '{"metadata":{"finalizers":null}}'
secret/harbor-token patched
[root@cce-uat-node03 ~]#
一般强制删除 kubernetes 的资源:
kubectl delete
强制删除不掉的话,可以使用:
kubectl patch