Skip to content

Instantly share code, notes, and snippets.

@benmoss
Created March 30, 2020 22:00
Show Gist options
  • Save benmoss/70ecbcc0593572cb7a409de236486e62 to your computer and use it in GitHub Desktop.
Save benmoss/70ecbcc0593572cb7a409de236486e62 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o pipefail
if [ -n "$VERBOSE" ]; then
set -o xtrace
fi
scratch=$(mktemp -d)
cleanup() {
rm -rf $scratch
}
trap cleanup EXIT
etcds=$(kubectl -n kube-system get pods -l component=etcd --field-selector=status.phase=Running -o jsonpath='{.items[*].metadata.name}')
echo $etcds | cut -d' ' -f1 | xargs -I{} kubectl -n kube-system cp {}:/etc/kubernetes/pki/etcd $scratch
export ETCDCTL_API=3
export ETCDCTL_CACERT=$scratch/ca.crt
export ETCDCTL_CERT=$scratch/peer.crt
export ETCDCTL_KEY=$scratch/peer.key
startingPort=5000
cmd=""
port=$(($startingPort-1))
for e in $etcds; do
port=$(($port+1))
cmd+="kubectl -n kube-system port-forward $e $port:2379 >/dev/null"
if [ -n "$VERBOSE" ]; then
cmd+=" & "
else
cmd+=" >/dev/null 2>&1 & "
fi
done
setsid sh -c "$cmd" &
pgid=$!
if [ -n "$VERBOSE" ]; then
echo "$cmd"
echo "Background tasks are running in process group $pgid, kill with kill -TERM -$pgid"
fi
etcdctl $(printf -- "--endpoints 127.0.0.1:%s " $(seq $startingPort $port)) member list -w table
etcdctl $(printf -- "--endpoints 127.0.0.1:%s " $(seq $startingPort $port)) endpoint status -w table
kill -TERM -$pgid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment