Skip to content

Instantly share code, notes, and snippets.

@notxcain
Last active December 6, 2017 08:28
Show Gist options
  • Select an option

  • Save notxcain/ac29f5526a89ab6348ec9c0d3c30ec38 to your computer and use it in GitHub Desktop.

Select an option

Save notxcain/ac29f5526a89ab6348ec9c0d3c30ec38 to your computer and use it in GitHub Desktop.
Continuously kill all pods except one randomly chosen.
#!/bin/bash
app=$1
chosen_one=$(kubectl get pods -l app=$app | tail -1 | awk '{print $1}')
echo "Keeping alive $chosen_one"
while true; do
pods=$(kubectl get pods -l app=$app | tail -n +2 | awk '{print $1}')
for pod in $pods; do
if [[ $pod != $chosen_one ]]; then
echo "Killing $pod"
kubectl delete po $pod
fi
done
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment