Last active
October 4, 2023 23:55
-
-
Save davidmroth/6fb597ca011ce57f6aa01f5a5ed5f3b8 to your computer and use it in GitHub Desktop.
Force delete all pods stuck in 'terminating' state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl delete pods --field-selector=status.phase=Failed | |
kubectl get replicaset --all-namespaces -o=jsonpath='{range .items[?(@.spec.replicas==0)]}{.metadata.name}{"\t"}{.metadata.namespace}{"\n"}{end}' | awk '{print $1 " --namespace=" $2}' | xargs -n 2 -d '\n' bash -c 'kubectl delete replicaset $0 $1' | |
kubectl delete pod --grace-period=0 --force $(k get pods | grep -v Running | grep -v ContainerCreating | tail -n +2 | awk '{print $1}') | |
# Fix terminating NS | |
NS=<NS> kubectl get namespace "$NS" -o json | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" | kubectl replace --raw /api/v1/namespaces/$NS/finalize -f - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment