Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Using this script you simply have to specify the first letters of a pod
  4. # to open a shell, the default shell is bash, but you can specify an
  5. # alternative as second parameter.
  6. #
  7. # For example, if you have the two following pods:
  8. # - caching-service-blablabla-123123-abcdef
  9. # - creditcard-frontend-blabla-3213213-fghijk
  10. #
  11. # And you want to get a bash shell into the second, you would do:
  12. # `kshell.sh cr`
  13. # ...and that should do the trick.
  14. #
  15. # And if you happend to have a pod with a container without bash, you
  16. # could do:
  17. # `kshell.sh cr sh`
  18. # and that will open sh instead of the default bash.
  19. #
  20. # If multiple pods match, the first one is selected. For exaple:
  21. # `kshell.sh c`
  22. # will probably give you a bash in the `caching-service...`
  23. #
  24. # This script doesn't support pods with multiple containers yet, if you
  25. # try to use it on these, you will get the familliar kubectl error about
  26. # you having to specify a container.
  27.  
  28.  
  29. if [ "$1" = "" ]; then
  30. echo "Usage: kshell [Pod] {shell (defaults to bash)}"
  31. exit 1
  32. fi
  33.  
  34. NEEDLE=$1
  35. SHELL=$2
  36. SHELL="${SHELL:-bash}"
  37.  
  38. COLUMNS=`tput cols`
  39. LINES=`tput lines`
  40. TERM=xterm
  41.  
  42. for name in `kubectl get pods -o json | jq '.items[].metadata.name' -r`; do
  43. if [[ $name == $NEEDLE* ]]; then
  44. kubectl exec -i -t $name env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM $SHELL
  45. exit 0
  46. fi
  47. done
  48.  
  49. echo "No Pod begining by $NEEDLE was found"
  50. exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement