diff --git a/README.md b/README.md index e69de29..19523b9 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,12 @@ +# my kubectl plugin scripts + +To install +``` +git https://git.rre.nu/jonas/kube-plugin.git "$HOME/kube-plugin" +export PATH=$PATH:$HOME/git/kube-plugin +``` + +Verify that the scripts are picked up in `kubectl` +``` +kubectl plugin list +``` diff --git a/kubectl-rsh b/kubectl-rsh new file mode 100755 index 0000000..1fa716c --- /dev/null +++ b/kubectl-rsh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +set -aeou pipefail + +SCRIPT_VERSION="0.1" +KUBECTL_RSH_IMAGE="${KUBECTL_RSH_IMAGE:-docker.io/library/busybox}" +KUBECTL_RSH_IMAGE_TAG="${KUBECTL_RSH_IMAGE_TAG:-latest}" +KUBECTL_RSH_NAMESPACE="${KUBECTL_RSH_NAMESPACE:-default}" +KUBECTL_RSH_POD_CREATE_TIMEOUT="${KUBECTL_RSH_POD_CREATE_TIMEOUT:-3}" + + +function print_help(){ + cat << EOF +Creates a pod on the node and executes a shell on that node. +You need cluster admin rights and privileged pod execution rights + +Usage: + kubectl rsh [nodeName] +EOF +} + +if [[ "$1" == "version" ]];then + echo "$SCRIPT_VERSION" + exit 0 +fi + +if [ "$1" == "--help" ]; then + print_help + exit 0 +fi + +NODE="$1" + +POD=$( kubectl create -n "$KUBECTL_RSH_NAMESPACE" -o name "$@" -f - </dev/null + +kubectl attach -n "$KUBECTL_RSH_NAMESPACE" -it "$POD" -c rsh-node "$@"