diff --git a/README.md b/README.md index 6e0340b..b120b14 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Option | Required | Description | Example -h | N | Show usage | *`kubectl ssh -h`* -d | N | Enable debug mode. Print a trace of each commands | *`kubectl ssh -d kafka-0`* -n | N | The namespace scope for this CLI request | *`kubectl ssh -n infra kafka-0`* +-C | N | The name of the kubeconfig context to use | *`kubectl ssh -C production kafka-0`* -u | N | User to exec as. Defaults to root | *`kubectl ssh -u kafka kafka-0`* -c | N | Specify container within pod | *`kubectl ssh -c burrow-metrics kafka-0`* -- | N | Pass an optional command. Defaults to /bin/sh | *`kubectl ssh kafka -- ls /etc/burrow`* diff --git a/kubectl-ssh b/kubectl-ssh index 5f92eb2..1ad1fed 100755 --- a/kubectl-ssh +++ b/kubectl-ssh @@ -15,6 +15,7 @@ Options: -n If present, the namespace scope for this CLI request -u Username or UID (format: [:]) -c Container name. If omitted, the first container in the pod will be chosen + -C The name of the kubeconfig context to use EOF exit 0 } @@ -37,12 +38,10 @@ COMMAND="/bin/sh" USERNAME="root" CONTAINER="NONE" NAMESPACE="NONE" +CONTEXT="NONE" -while getopts "hdp:n:u:c:" arg; do +while getopts "hdn:u:c:C:" arg; do case $arg in - p) # Specify pod name. - POD=${OPTARG} - ;; n) # Specify namespace NAMESPACE=${OPTARG} KUBECTL+=" --namespace=${OPTARG}" @@ -53,6 +52,10 @@ while getopts "hdp:n:u:c:" arg; do c) # Specify container CONTAINER=${OPTARG} ;; + C) # Specify context + CONTEXT=${OPTARG} + KUBECTL+=" --context=${OPTARG}" + ;; d) # Enable debug mode set -x ;; @@ -83,7 +86,16 @@ if [[ $# -gt 0 ]]; then fi fi -echo -e "\nConnecting...\nPod: ${POD}\nNamespace: ${NAMESPACE}\nUser: ${USERNAME}\nContainer: ${CONTAINER}\nCommand: $COMMAND\n" +cat <