Created
July 21, 2016 20:36
-
-
Save Stono/dcf91b94fd68a50ce1eaa76ed70957e1 to your computer and use it in GitHub Desktop.
A shell script which enables easy execing into kube pods
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
#!/bin/sh | |
if [ "$1" = "" ]; then | |
echo "Usage: kshell <pod>" | |
exit 1 | |
fi | |
echo Getting pods... | |
PODS=$(kubectl get pods --no-headers --output=name | grep $1) | |
PODS=(${PODS}) | |
NUM_PODS=${#PODS[@]} | |
if [ $NUM_PODS -gt 1 ]; then | |
echo Your search matched multiple pods, please be more specific: | |
for pod in "${PODS[@]}" ; do # <- quotes required | |
echo " - $pod" | |
done | |
exit 1 | |
fi | |
POD=${PODS[0]} | |
POD=${POD/pod\//} | |
echo Connecting to $POD... | |
COLUMNS=`tput cols` | |
LINES=`tput lines` | |
TERM=xterm | |
kubectl exec -i -t $POD env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful...Forked to let you choose a pod from the list.