Skip to content

Instantly share code, notes, and snippets.

@christophetd christophetd/run.sh Secret
Created Mar 30, 2020

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.