Last active
December 24, 2021 03:20
-
-
Save zryfish/e6d6c538206fc32b32a1b1c45765cd73 to your computer and use it in GitHub Desktop.
nsenter-node.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -x | |
| node=${1} | |
| nodeName=$(kubectl get node ${node} -o template --template='{{index .metadata.labels "kubernetes.io/hostname"}}') | |
| nodeSelector='"nodeSelector": { "kubernetes.io/hostname": "'${nodeName:?}'" },' | |
| podName=exec-${node} | |
| kubectl run ${podName:?} --restart=Never -it --rm --image overriden --overrides ' | |
| { | |
| "spec": { | |
| "hostPID": true, | |
| "hostNetwork": true, | |
| '"${nodeSelector?}"' | |
| "tolerations": [{ | |
| "operator": "Exists" | |
| }], | |
| "containers": [ | |
| { | |
| "name": "nsenter", | |
| "image": "ubuntu:focal", | |
| "command": [ | |
| "/bin/bash" | |
| ], | |
| "stdin": true, | |
| "tty": true, | |
| "securityContext": { | |
| "privileged": true | |
| } | |
| } | |
| ] | |
| } | |
| }' --attach "$@" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From https://alexei-led.github.io/post/k8s_node_shell/