-
-
Save tamalsaha/4e6a5c1144e2daf370398520e20fdef7 to your computer and use it in GitHub Desktop.
Kubectl exec with working terminal
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: ksh <pod> [flags_to_kubectl]" | |
exit 1 | |
fi | |
POD=$1 | |
shift | |
COLUMNS=`tput cols` | |
LINES=`tput lines` | |
TERM=xterm | |
KUBE_SHELL=${KUBE_SHELL:-bash} | |
kubectl exec -i -t $POD "$@" -- env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM "$KUBE_SHELL" |
And one for the bashrc or .functions if your a dotfiles man.
function ksh() {
if [ $1 = "" ]; then
echo "Usage: ksh <pod> [flags_to_kubectl]"
return 1
fi
local POD=$1
shift
local COLUMNS=$(tput cols)
local LINES=$(tput lines)
local TERM=xterm
local KUBE_SHELL=${KUBE_SHELL:-/bin/sh -il}
local cmd="kubectl exec -i -t $POD $@ -- env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM $KUBE_SHELL"
echo $cmd
eval $cmd
}
Thanks @coresolve !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I originally found this on Kubernetes slack channel. I adapted it so that it can be used with pods running in any namespace. Example: