Skip to content

Instantly share code, notes, and snippets.

@ams0
Created September 17, 2019 08:18
Show Gist options
  • Save ams0/775bb279e8ae0811bf9a1c3b14087582 to your computer and use it in GitHub Desktop.
Save ams0/775bb279e8ae0811bf9a1c3b14087582 to your computer and use it in GitHub Desktop.
#!/bin/sh
#https://itnext.io/get-a-shell-to-a-kubernetes-node-9b720a15a4fe
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=${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