Skip to content

Instantly share code, notes, and snippets.

@christophetd
Created March 30, 2020 19:12
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 christophetd/fdff4d169f47f23d14f9e43e4d59997f to your computer and use it in GitHub Desktop.
Save christophetd/fdff4d169f47f23d14f9e43e4d59997f to your computer and use it in GitHub Desktop.
#!/bin/bash
cmd="$1"
nodes=$(k3s kubectl get nodes -o json | jq -r '.items[].metadata.labels["kubernetes.io/hostname"]' | sort)
while read node; do
if [[ $node -eq "$HOSTNAME" ]]; then
continue
fi
echo "> $node:";
nodeSelector='"nodeSelector": { "kubernetes.io/hostname": "'$node'" },'
podName=$USER-nsenter-$node
k3s kubectl delete pod $podName 2>/dev/null
k3s kubectl run --quiet $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", "--", "bash", "-c", "'${cmd}'"
],
"securityContext": {
"privileged": true
}
}
]
}
}'
echo
done <<< $nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment