Skip to content

Instantly share code, notes, and snippets.

@superseb
Last active August 15, 2019 20:15
Show Gist options
  • Save superseb/117efe9faaa6655c7483e92209033c6d to your computer and use it in GitHub Desktop.
Save superseb/117efe9faaa6655c7483e92209033c6d to your computer and use it in GitHub Desktop.
Get RKE config for worker node in Rancher 2.x
#!/bin/bash
# Warning, this is not official documentation
### For PODS (when cattle-node-agent are deployed as pods)
# Show all config
docker exec $(docker ps --filter=label=io.cattle.agent=true --filter=name=node-agent --format='{{.ID}}') bash -c 'PARAMS=$(echo {\"Node\":{\"requestedHostname\":\"$(echo $CATTLE_NODE_NAME)\"}} | base64 -w0); curl -s -k -H "X-API-Tunnel-Token: $(cat /cattle-credentials/token)" -H "X-Api-Tunnel-Params: "$(echo $PARAMS)"" "$(cat /cattle-credentials/url)/v3/connect/config"'
# Show processes and images
docker exec $(docker ps --filter=label=io.cattle.agent=true --filter=name=node-agent --format='{{.ID}}') bash -c 'PARAMS=$(echo {\"Node\":{\"requestedHostname\":\"$(echo $CATTLE_NODE_NAME)\"}} | base64 -w0); curl -s -k -H "X-API-Tunnel-Token: $(cat /cattle-credentials/token)" -H "X-Api-Tunnel-Params: "$(echo $PARAMS)"" "$(cat /cattle-credentials/url)/v3/connect/config" | jq ".processes[] | .name, .image"'
### For docker run agents (when node has not joined the cluster yet
# Show all config
docker exec $(docker ps --filter=label=io.cattle.agent=true --format='{{.ID}}' | head -1) bash -c 'PARAMS=$(echo {\"Node\":{\"requestedHostname\":\"$(hostname)\"}} | base64); curl -s -k -H "X-API-Tunnel-Token: $(docker inspect $(docker ps --filter=label=io.cattle.agent=true --format={{.ID}} | head -1) | grep -A1 \"\-\-token\" | tail -1 | tr -s " " | sed s/\"//g | sed "s/ //g" | sed "s/,//g")" -H "X-Api-Tunnel-Params: "$(echo $PARAMS)"" "$(docker inspect $(docker ps --filter=label=io.cattle.agent=true --format={{.ID}} | head -1) | grep -A1 \"\-\-server\" | tail -1 | tr -s " " | sed s/\"//g | sed "s/ //g" | sed "s/,//g")/v3/connect/config"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment