Skip to content

Commit 6abf81a

Browse files
authored
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
1 parent a25bf63 commit 6abf81a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fubectl.source

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ function kcmd() {
6767
local image="${2:-ubuntu}"
6868
local ns="$(kubectl get ns | _inline_fzf | awk '{print $1}')"
6969
if [ -n "$cmd" ]; then
70-
kubectl run shell-$RANDOM --namespace $ns --rm -i --tty --image ${image} -- /bin/sh -c "${cmd}"
70+
kubectl run shell-$RANDOM --pod-running-timeout 600s --namespace $ns --rm -i --tty --image ${image} -- /bin/sh -c "${cmd}"
7171
else
72-
kubectl run shell-$RANDOM --namespace $ns --rm -i --tty --image ${image} -- /bin/bash
72+
kubectl run shell-$RANDOM --pod-running-timeout 600s --namespace $ns --rm -i --tty --image ${image} -- /bin/bash
7373
fi
7474
}
7575

@@ -316,6 +316,18 @@ function ktree() {
316316
fi
317317
}
318318

319+
# [kssh] select the external node IP to connect to the node via SSH. If external IP is not set, internal IP is used.
320+
function kssh() {
321+
local user=${1:-root}
322+
local node_name="$(kubectl get node -o wide | _inline_fzf | awk '{print $1}')"
323+
local node_ext_ip="$(kubectl get node -o wide --no-headers $node_name | awk '{print $7}')"
324+
if [[ "$node_ext_ip" == "<none>" ]]; then
325+
local node_ext_ip="$(kubectl get node -o wide --no-headers $node_name | awk '{print $6}')"
326+
fi
327+
echo "ssh $user@$node_ext_ip"
328+
ssh $user@$node_ext_ip
329+
}
330+
319331
# [konsole] create root shell on a node
320332
function konsole() {
321333
local node_hostname="$(kubectl get node --label-columns=kubernetes.io/hostname | _inline_fzf | awk '{print $6}')"

0 commit comments

Comments
 (0)