Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mvasilenko/316ce0399ce8a95bc3e6ab0d1b71e882 to your computer and use it in GitHub Desktop.
Save mvasilenko/316ce0399ce8a95bc3e6ab0d1b71e882 to your computer and use it in GitHub Desktop.
delete k8s pods stuck in Terminating state
#!/bin/bash
# get namespaces list
NAMESPACES=$(kubectl get namespaces --output=jsonpath={.items..metadata.name})
# delete stuck pods in each namespace
for NS in $NAMESPACES;do
kubectl get pods -n $NS | awk "\$3==\"Terminating\" {print \"kubectl delete -n $NS pod \" \$1 \" --grace-period=0 --force\"}" | xargs -0 bash -c
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment