Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Created February 27, 2018 09:06
Show Gist options
  • Save Mikulas/61171bc874c2c9bdceefd9b8977070c0 to your computer and use it in GitHub Desktop.
Save Mikulas/61171bc874c2c9bdceefd9b8977070c0 to your computer and use it in GitHub Desktop.
Gracefully recreate nginx pod in kubernetes daemonset
#!/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