Skip to content

Instantly share code, notes, and snippets.

@agonzalezro
Last active May 23, 2017 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agonzalezro/82616714cdce78a4c6b8500361a06540 to your computer and use it in GitHub Desktop.
Save agonzalezro/82616714cdce78a4c6b8500361a06540 to your computer and use it in GitHub Desktop.

Change the number of REPLICAS to make it easier or harder.

demo

$ bash game.sh
I have launched 2 Pods in a Replica Set, are you quicker eliminating
them than Kubernetes recreating them? Let's see!

To terminate a pod you need to write its ID as quick as you can. GO!

...

Try to terminate: 1521l
> a
Wrong ID!

Try to terminate: 1521l
> 1521l
Cool, you did it!

Try to terminate: 246rt
> 246rt
Cool, you did it!

You have win, congratulations!

TODO

  • Wait for a proper cleanup.
  • Wait for at least having one container running instead just sleeping.
#!/bin/bash
NAME=thegame
REPLICAS=5
trap ctrl_c INT
function ctrl_c() {
end
}
function start() {
kubectl create namespace $NAME &> /dev/null
kubectl run $NAME --replicas=$REPLICAS --image=alpine --namespace=$NAME --command -- sleep 1h &> /dev/null
cat <<EOF
I have launched $REPLICAS Pods in a Replica Set, are you quicker eliminating
them than Kubernetes recreating them? Let's see!
To terminate a pod you need to write its ID as quick as you can. GO!
...
EOF
sleep 5s # TODO: instead sleep wait for a pod to start running
}
function end() {
kubectl delete namespace $NAME &> /dev/null
exit 0
}
function print_id_message {
ID=$(kubectl get pods --namespace=$NAME|\
grep "Running"|\
head -n1|\
awk '{ print $1 }'|\
awk -F- '{ print $NF }')
if [ "$ID" == "" ]; then
echo "You have win, congratulations!"
end
fi
echo -n "Try to terminate: "
echo $ID
}
start
while [ 1 ]; do
print_id_message
read -p "> " id
kubectl delete --namespace=$NAME $(kubectl get pods --namespace=$NAME -o=name|egrep -e "-$id$") &> /dev/null
if [[ "$?" == 0 ]]; then
echo "Cool, you did it!"
else
echo "Wrong ID!"
fi
echo ""
done
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment