Last active
March 26, 2020 19:02
-
-
Save leodido/eb71ce6a140c48d422131b6bade6cb50 to your computer and use it in GitHub Desktop.
Exec into a node with kubectl
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
#!/usr/bin/env bash | |
NODE=kind-control-plane | |
IMG="docker.io/library/alpine" | |
POD="nsenter-$(tr -dc a-z0-9 < /dev/urandom | head -c 6)" | |
OVERRIDE="{\"spec\":{\"nodeName\":\"$NODE\",\"hostPID\":true,\"containers\":[{\"securityContext\":{\"privileged\":true},\"image\":\"${IMG}\",\"name\":\"nsenter\",\"stdin\":true,\"stdinOnce\":true,\"tty\":true,\"command\":[\"nsenter\",\"--target\",\"1\",\"--mount\",\"--uts\",\"--ipc\",\"--net\",\"--pid\",\"--\",\"bash\",\"-l\"]}]}}" | |
kubectl run --rm \ | |
--image "${IMG}" \ | |
--overrides="${OVERRIDE}" \ | |
--generator=run-pod/v1 \ | |
-ti "${POD}" \ | |
-n default |
TODO LIST
- flags and minimal validation
- node name
- namespace
- check node exists
- check kubectl exists
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy it and execute.
You can download it as follows: