Skip to content

Instantly share code, notes, and snippets.

@jamesholcomb
Forked from Stono/kshell
Last active March 13, 2018 21:33
Show Gist options
  • Save jamesholcomb/b642f3459c203836f59aee2e0528e46c to your computer and use it in GitHub Desktop.
Save jamesholcomb/b642f3459c203836f59aee2e0528e46c to your computer and use it in GitHub Desktop.
A shell script which enables easy execing into kube pods
#!/bin/sh
if [ "$1" = "" ]; then
echo "Usage: ./ksh <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 Choose a pod:
select pod in "${PODS[@]}"
do
POD=${pod/pods\//}
break
done
else
POD=${PODS[0]/pods\//}
fi
echo Connecting to $POD...
COLUMNS=`tput cols`
LINES=`tput lines`
TERM=xterm
kubectl exec -it $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