From ab883823c1e5a74871949534de25034eba8595e4 Mon Sep 17 00:00:00 2001 From: Olivier Grand Date: Mon, 8 Jan 2024 14:29:49 +0100 Subject: [PATCH] add k9s plugin tu run shell from nodes --- tools/k9s-plugins.yml | 12 ++++++++++++ tools/root-shell.sh | 8 ++++++++ 2 files changed, 20 insertions(+) create mode 100755 tools/root-shell.sh diff --git a/tools/k9s-plugins.yml b/tools/k9s-plugins.yml index 48555e5..75248b5 100644 --- a/tools/k9s-plugins.yml +++ b/tools/k9s-plugins.yml @@ -1,4 +1,16 @@ plugin: + #--- Open root shell from nodes + node-shell: + shortCut: Shift-S + description: Root shell + scopes: + - nodes + command: bash + background: false + confirm: true + args: + - -c + - "root-shell.sh $NAME" #--- Get events for selected k8s objects every 5s watch-events: shortCut: Shift-E diff --git a/tools/root-shell.sh b/tools/root-shell.sh new file mode 100755 index 0000000..173b008 --- /dev/null +++ b/tools/root-shell.sh @@ -0,0 +1,8 @@ +#!/bin/bash +#=========================================================================== +# Open root shell from node +#=========================================================================== + +export NAME="$1" +kubectl run tmp-shell --rm -i --tty --overrides='{"spec": {"hostNetwork": true, "hostIPC": true, "hostPID": true, "nodeSelector": {"k3s.io/hostname":"'"$NAME"'"}, "volumes": [{"name": "root-mount", "hostPath": {"path": "/"}}], "containers": [{"name":"tmp-shell", "stdin": true, "stdinOnce": true, "image":"nicolaka/netshoot:v0.11", "tty":true, "volumeMounts": [{"name": "root-mount", "mountPath": "/host-root"}], "securityContext": {"privileged": true, "allowPrivilegeEscalation": true}}]}}' --image nicolaka/netshoot +sleep 7 \ No newline at end of file