Created
November 6, 2018 21:16
-
-
Save roopakv/0c02325fe871ac65193c2f662f6e5880 to your computer and use it in GitHub Desktop.
restart kubernetes pod with a script
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
echo "sleeping for ${SLEEP_TIME_BEFORE_RESTART:=86400} seconds" | |
sleep ${SLEEP_TIME_BEFORE_RESTART:=86400}s # Sleep for a day | |
curl -LO https://storage.googleapis.com/our-ops/artifacts/kubectl | |
chmod +x ./kubectl | |
if [ -z "$KUBE_DEPLOYMENT_TO_RESTART" ] || [ -z "$KUBE_CONTAINER_TO_SET_VAR" ] | |
then | |
echo "I haven't been told which deployment to restart! skipping" | |
else | |
RESTART_PATCH='' read -r -d '' RESTART_PATCH <<EOF | |
{ | |
"spec": { | |
"template": { | |
"spec": { | |
"containers": [ | |
{ | |
"name": "${KUBE_CONTAINER_TO_SET_VAR}", | |
"env": [ | |
{ | |
"name":"RESTART_", | |
"value": "$(date -uIseconds)" | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
EOF | |
./kubectl patch deployment ${KUBE_DEPLOYMENT_TO_RESTART} -p'${RESTART_PATCH}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment