Skip to content

Instantly share code, notes, and snippets.

@echo-devnull
Created November 4, 2022 21:01
Show Gist options
  • Save echo-devnull/f9d1ed316a810e6d0635fda219f7a533 to your computer and use it in GitHub Desktop.
Save echo-devnull/f9d1ed316a810e6d0635fda219f7a533 to your computer and use it in GitHub Desktop.
Creating a container thas has access to the node it's running on
r00t() {
if [ -n "$1" ]
then
kubectl run r00t --restart=Never -it --rm --image f00 --overrides "{\"spec\":{\"hostNetwork\": true, \"hostPID\": true, \"containers\": [{\"name\":\"1\",\"image\":\"alpine\",\"command\":[\"nsenter\",\"--mount=/proc/1/ns/mnt\",\"--\",\"/bin/sh\"],\"stdin\":true, \"tty\":true,\"securityContext\":{\"privileged\":true}}],\"nodeSelector\":{\"kubernetes.io/hostname\":\"$1\"},\"tolerations\":[{\"key\":\"node-role.kubernetes.io/etcd\",\"operator\":\"Exists\",\"effect\":\"NoExecute\"},{\"key\":\"node-role.kubernetes.io/controlplane\",\"operator\":\"Exists\",\"effect\":\"NoSchedule\"}]}}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment