Last active
January 18, 2020 16:06
-
-
Save jlcrow/45dcf47d71891e180911ce4e43240c9d to your computer and use it in GitHub Desktop.
rollStatefulset.sh
This file contains hidden or 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
#!/usr/bin/env bash | |
NAMESPACE=$1 | |
STATEFULSET=$2 | |
CONTAINER=$3 | |
COMMAND=$4 | |
GREP=$5 | |
REPLICAS=$(kubectl -n $NAMESPACE get statefulset $STATEFULSET -o=jsonpath='{.status.currentReplicas}') | |
COUNT=$(($REPLICAS-1)) | |
while [ $COUNT -gt -1 ]; do | |
DELCMD=$(kubectl -n $NAMESPACE delete pod $STATEFULSET-$COUNT) | |
echo $DELCMD | |
STATUS="-1" | |
while [ $STATUS -ne "0" ]; do | |
TEST=$(kubectl -n $NAMESPACE exec -it -c $CONTAINER $STATEFULSET-$COUNT -- $COMMAND | grep $GREP) | |
let STATUS=$? | |
echo "$TEST - $STATUS" | |
SLEEP 2 | |
done | |
RESULT=$(kubectl -n $NAMESPACE get statefulset $STATEFULSET) | |
let COUNT=COUNT-1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an attempt to do a controlled roll of a statefulset by deleting the pods in reverse order but allowing a check command to run so that the next pod is not rolled until some sort of ready state is reached - this requires kubectl to be intialized to a cluster before running.
ex.
./rollStatefulset.sh redis rfr-redis-hybris-dev redis "redis-cli role" "master\|slave"