Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Created September 19, 2022 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertrandmartel/42e8fbc83f7c7243e80d5ef3a0a1d9e7 to your computer and use it in GitHub Desktop.
Save bertrandmartel/42e8fbc83f7c7243e80d5ef3a0a1d9e7 to your computer and use it in GitHub Desktop.
Delete all stuck pods from a list of pod in a file
#!/bin/bash
while IFS= read -r pod; do
echo $pod
namespace=$(kubectl get pods -o wide --all-namespaces -o custom-columns=":metadata.name, :metadata.namespace" | grep $pod | awk '{print $2}')
if [ -n "$namespace" ]; then
echo "deleting $pod on namespace $namespace"
kubectl delete pod $pod --grace-period=0 --force -n $namespace
else
echo "$pod was not found."
fi
done < evicted.txt
pod-1
pod-2
pod-3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment