Skip to content

Instantly share code, notes, and snippets.

@oskapt
Forked from superseb/restore_rancher2_agents.md
Created August 2, 2019 01:49
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 oskapt/d0b179c7010f697ef50e47c0401e5aaa to your computer and use it in GitHub Desktop.
Save oskapt/d0b179c7010f697ef50e47c0401e5aaa to your computer and use it in GitHub Desktop.
Restore Rancher 2 cluster/node agents on clusters

Restore Rancher 2 cluster/node agents on clusters

This is an unsupported scenario, see rancher/rancher#14731 when there is an official solution.

When cattle-cluster-agent and/or cattle-node-agent are accidentally deleted, or when server-url/cacerts are changed.

Generate definitions

  • Generate API token in the UI (user -> API & Keys) and save the Bearer token
  • Find the clusterid in the Rancher UI (format is c-xxxxx), its in the address bar when the cluster is selected
  • Generate agent definitions (needs curl, jq)
# Rancher URL
RANCHERURL="https://rancher.mydomain.com"
# Cluster ID
CLUSTERID="c-xxxxx"
# Token
TOKEN="token-xxxxx:xxxxx"
# Valid certificates
curl -s -H "Authorization: Bearer ${TOKEN}" "${RANCHERURL}/v3/clusterregistrationtokens?clusterId=${CLUSTERID}" | jq -r '.data[] | select(.name != "system") | .command'
# Self signed certificates
curl -s -k -H "Authorization: Bearer ${TOKEN}" "${RANCHERURL}/v3/clusterregistrationtokens?clusterId=${CLUSTERID}" | jq -r '.data[] | select(.name != "system") | .insecureCommand'

Apply definitions

The generated command needs to be executed using kubectl configured with a kubeconfig to talk to the cluster. See the gists below to retrieve the kubeconfig:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment