Skip to content

Instantly share code, notes, and snippets.

@Alevsk
Forked from jjo/kubectl-root-in-host.sh
Created July 30, 2021 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alevsk/e4e8b0a37832e1ad0bcaa212ab2fc00d to your computer and use it in GitHub Desktop.
Save Alevsk/e4e8b0a37832e1ad0bcaa212ab2fc00d to your computer and use it in GitHub Desktop.
#!/bin/sh
node=${1}
if [ -n "${node}" ]; then
nodeSelector='"nodeSelector": { "kubernetes.io/hostname": "'${node:?}'" },'
else
nodeSelector=""
fi
set -x
kubectl run ${USER+${USER}-}sudo --restart=Never -it \
--image overriden --overrides '
{
"spec": {
"hostPID": true,
"hostNetwork": true,
'"${nodeSelector?}"'
"containers": [
{
"name": "busybox",
"image": "alpine:3.7",
"command": ["nsenter", "--mount=/proc/1/ns/mnt", "--", "sh", "-c", "hostname sudo--$(cat /etc/hostname); exec /bin/bash"],
"stdin": true,
"tty": true,
"resources": {"requests": {"cpu": "10m"}},
"securityContext": {
"privileged": true
}
}
]
}
}' --rm --attach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment