强制删除资源
强制删除 pod
kubectl get namespace olm -o json | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" | kubectl replace --raw /api/v1/namespaces/olm/finalize -f -
kubectl get namespace operators -o json | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" | kubectl replace --raw /api/v1/namespaces/operators/finalize -f -
- Pod 删除失败
export namespace=test-ns
export pod_name=mysql-cluster-0
kubectl patch pod -n $namespace $pod_name -p '{"metadata":{"finalizers":null}}'
- crd 资源
export namespace=test-ns
export crd_name=mysql-cluster
kubectl patch InnoDBCluster -n $namespace $crd_name -p '{"metadata":{"finalizers":null}}
ns 删除失败
先查看需要删除的 ns
获取所有文件的 json,并注意核对列表
kubectl get ns |grep Terminating | awk '{print $1}' | xargs -i bash -c "kubectl get ns {} -o json > {}"
ls | xargs -i jq '.metadata.name' {}
更改 json 文件,去除 .spec.finalizers
字段
# 先确定字段
ls | xargs -i jq '.metadata.name, .spec.finalizers' {}
# 删除字段
mkdir delete
ls | xargs -i bash -c "jq 'del(.spec.finalizers[])' {} > delete/{}"
# 再次确定字段
cd delete
ls | xargs -i jq '.metadata.name, .spec.finalizers' {}
转发 kube-apiserver
提交修改
ls | xargs -i curl -k -H "Content-Type: application/json" -X PUT --data-binary @{} http://127.0.0.1:8081/api/v1/namespaces/{}/finalize
级联删除失败
https://www.cnblogs.com/kirito-c/p/14022707.html
Kubernetes 的级联管理功能失效:
- 删除 Replicaset 时,Pod 不会被级联删除
- 删除 Cronjob 时不会级联删除 Job
- 删除 Job 时,也不会自动删除对应的 Pod
Kube-controller 报如下日志:
garbagecollector.go:228] timed out waiting for dependency graph builder sync during GC sync (attempt 816)
级联删除是垃圾收集器提供的
replicaset/cronjob 都是 controller 类型,查看 controller 日志,主节点上的 controller 有报错:
E0225 17:58:11.106185 1 resource_quota_controller.go:408] unable to retrieve the complete list of server APIs: authorization.openshift.io/v1: the server is currently unable to handle the request, project.openshift.io/v1: the server is currently unable to handle the request
E0225 17:58:12.694600 1 memcache.go:196] couldn't get resource list for project.openshift.io/v1: the server is currently unable to handle the request
E0225 17:58:12.744473 1 memcache.go:196] couldn't get resource list for authorization.openshift.io/v1: the server is currently unable to handle the request
E0225 17:58:13.744610 1 memcache.go:101] couldn't get resource list for authorization.openshift.io/v1: the server is currently unable to handle the request
E0225 17:58:13.794373 1 memcache.go:101] couldn't get resource list for project.openshift.io/v1: the server is currently unable to handle the request
https://www.cnblogs.com/lianngkyle/p/15333559.html