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 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'
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:
- Get kubeconfig for custom cluster in Rancher 2.x: https://gist.github.com/superseb/f6cd637a7ad556124132ca39961789a4
- Retrieve kubeconfig from RKE v0.1.x or Rancher v2.0.x/v2.1.x custom cluster controlplane node: https://gist.github.com/superseb/3d8de6092ebc4b1581185197583f472a
- Retrieve kubeconfig from RKE v0.2.x or Rancher v2.2.x custom cluster controlplane node: https://gist.github.com/superseb/b14ed3b5535f621ad3d2aa6a4cd6443b