Created
February 27, 2018 09:06
-
-
Save Mikulas/61171bc874c2c9bdceefd9b8977070c0 to your computer and use it in GitHub Desktop.
Gracefully recreate nginx pod in kubernetes daemonset
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 | |
set -euo pipefail | |
IFS=$'\n\t' | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
function test-stable { | |
for PHASE in $(kubectl -n kube-system get pods -l app=nginx -o json | jq -r '.items[].status.phase'); do | |
if [[ "$PHASE" != "Running" ]]; then | |
echo "pod is $PHASE, waiting" | |
return 1 | |
fi | |
done | |
return 0 | |
} | |
function await-stable { | |
while ! test-stable; do | |
sleep 3 | |
done | |
echo "all nginx pods are running" | |
} | |
for POD_ID in $(kubectl -n kube-system get pods -l app=nginx -o json | jq -r '.items[].metadata.name'); do | |
echo "$POD_ID" | |
kubectl -n kube-system delete pod "$POD_ID" | |
await-stable | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment