From 6abf81a4d275d49351127458d4dd8f6468f0366a Mon Sep 17 00:00:00 2001 From: Tobias Schneck Date: Mon, 24 Jun 2024 10:40:33 +0200 Subject: [PATCH] Add kssh + smaller kcmd improvement (#102) * add longer timeout for kcmd ensures that bigger images could get downloaded in time * add kssh to quickly open an SSH connection to a node --- fubectl.source | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fubectl.source b/fubectl.source index 076c24e..4aef0b6 100755 --- a/fubectl.source +++ b/fubectl.source @@ -67,9 +67,9 @@ function kcmd() { local image="${2:-ubuntu}" local ns="$(kubectl get ns | _inline_fzf | awk '{print $1}')" if [ -n "$cmd" ]; then - kubectl run shell-$RANDOM --namespace $ns --rm -i --tty --image ${image} -- /bin/sh -c "${cmd}" + kubectl run shell-$RANDOM --pod-running-timeout 600s --namespace $ns --rm -i --tty --image ${image} -- /bin/sh -c "${cmd}" else - kubectl run shell-$RANDOM --namespace $ns --rm -i --tty --image ${image} -- /bin/bash + kubectl run shell-$RANDOM --pod-running-timeout 600s --namespace $ns --rm -i --tty --image ${image} -- /bin/bash fi } @@ -316,6 +316,18 @@ function ktree() { fi } +# [kssh] select the external node IP to connect to the node via SSH. If external IP is not set, internal IP is used. +function kssh() { + local user=${1:-root} + local node_name="$(kubectl get node -o wide | _inline_fzf | awk '{print $1}')" + local node_ext_ip="$(kubectl get node -o wide --no-headers $node_name | awk '{print $7}')" + if [[ "$node_ext_ip" == "" ]]; then + local node_ext_ip="$(kubectl get node -o wide --no-headers $node_name | awk '{print $6}')" + fi + echo "ssh $user@$node_ext_ip" + ssh $user@$node_ext_ip +} + # [konsole] create root shell on a node function konsole() { local node_hostname="$(kubectl get node --label-columns=kubernetes.io/hostname | _inline_fzf | awk '{print $6}')"