Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`*
Expand Down
22 changes: 17 additions & 5 deletions kubectl-ssh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Options:
-n If present, the namespace scope for this CLI request
-u Username or UID (format: <name|uid>[:<group|gid>])
-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
}
Expand All @@ -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}"
Expand All @@ -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
;;
Expand Down Expand Up @@ -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 <<EOF
Connecting...
Pod: ${POD}
Namespace: ${NAMESPACE}
Context: ${CONTEXT}
User: ${USERNAME}
Container: ${CONTAINER}
Command: ${COMMAND}
EOF

# $temp_container is the name of our temporary container which we use to connect behind the scenes. Will be cleaned up automatically.
temp_container="ssh-pod-${RANDOM}"

Expand Down