Skip to content

Commit

Permalink
add k9s plugin tu run shell from nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrand committed Jan 8, 2024
1 parent b38d2db commit ab88382
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/k9s-plugins.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions tools/root-shell.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ab88382

Please sign in to comment.