Created
January 27, 2022 09:21
-
-
Save omadjoudj/dde7c197cead5c7f22c2d73bfb93e6de to your computer and use it in GitHub Desktop.
Getting a shell to a Node in K8s
This file contains 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 | |
node=${1} | |
nodeName=$(kubectl get node ${node} -o template --template='{{index .metadata.labels "kubernetes.io/hostname"}}') | |
nodeSelector='"nodeSelector": { "kubernetes.io/hostname": "'${nodeName:?}'" },' | |
podName=${USER}-nsenter-${node} | |
kubectl run ${podName:?} --restart=Never -it --rm --image overriden --overrides ' | |
{ | |
"spec": { | |
"hostPID": true, | |
"hostNetwork": true, | |
'"${nodeSelector?}"' | |
"tolerations": [{ | |
"operator": "Exists" | |
}], | |
"containers": [ | |
{ | |
"name": "nsenter", | |
"image": "alexeiled/nsenter:2.34", | |
"command": [ | |
"/nsenter", "--all", "--target=1", "--", "su", "-" | |
], | |
"stdin": true, | |
"tty": true, | |
"securityContext": { | |
"privileged": true | |
} | |
} | |
] | |
} | |
}' --attach "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment