Skip to content

Commit

Permalink
Add kssh + smaller kcmd improvement (#102)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
toschneck authored Jun 24, 2024
1 parent a25bf63 commit 6abf81a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions fubectl.source
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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" == "<none>" ]]; 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}')"
Expand Down

0 comments on commit 6abf81a

Please sign in to comment.