Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Using this script you simply have to specify the first letters of a pod
- # to open a shell, the default shell is bash, but you can specify an
- # alternative as second parameter.
- #
- # For example, if you have the two following pods:
- # - caching-service-blablabla-123123-abcdef
- # - creditcard-frontend-blabla-3213213-fghijk
- #
- # And you want to get a bash shell into the second, you would do:
- # `kshell.sh cr`
- # ...and that should do the trick.
- #
- # And if you happend to have a pod with a container without bash, you
- # could do:
- # `kshell.sh cr sh`
- # and that will open sh instead of the default bash.
- #
- # If multiple pods match, the first one is selected. For exaple:
- # `kshell.sh c`
- # will probably give you a bash in the `caching-service...`
- #
- # This script doesn't support pods with multiple containers yet, if you
- # try to use it on these, you will get the familliar kubectl error about
- # you having to specify a container.
- if [ "$1" = "" ]; then
- echo "Usage: kshell [Pod] {shell (defaults to bash)}"
- exit 1
- fi
- NEEDLE=$1
- SHELL=$2
- SHELL="${SHELL:-bash}"
- COLUMNS=`tput cols`
- LINES=`tput lines`
- TERM=xterm
- for name in `kubectl get pods -o json | jq '.items[].metadata.name' -r`; do
- if [[ $name == $NEEDLE* ]]; then
- kubectl exec -i -t $name env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM $SHELL
- exit 0
- fi
- done
- echo "No Pod begining by $NEEDLE was found"
- exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement