Skip to content

Instantly share code, notes, and snippets.

@Stono
Created July 21, 2016 20:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Stono/dcf91b94fd68a50ce1eaa76ed70957e1 to your computer and use it in GitHub Desktop.
Save Stono/dcf91b94fd68a50ce1eaa76ed70957e1 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: 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
@jamesholcomb
Copy link

jamesholcomb commented Mar 13, 2018

Very helpful...Forked to let you choose a pod from the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment