Last active
May 30, 2023 03:12
-
-
Save rahulkj/3609d12ecc953bc11ae82e0d3729d02d to your computer and use it in GitHub Desktop.
Cleanup pods that are in a bad 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
#!/bin/bash | |
CODES=("Error" "ContainerStatusUnknown" "Evicted" "CrashLoopBackOff" "Completed" "OOMKilled" "ImagePullBackOff" "ErrImagePull") | |
for code in "${CODES[@]}"; do | |
echo "Looking for pods that are in ${code} status" | |
PODS=($(kubectl get pods --all-namespaces | grep ${code} | awk '{print $2 "|" $1}')) | |
for pod in "${PODS[@]}"; do | |
echo "$pod" | awk -F"|" '{print $1 " --namespace=" $2}' | xargs kubectl delete pod; | |
done | |
echo "Moving onto the next" | |
echo "---------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment