rancher: [BUG] Cattle-Node-Agent Deletes In-use Cattle-Credentials Secret Causing new Cluster-Agent or node-Agent failed to run

Rancher Server Setup

  • Rancher version: 2.9.9, 2.10.5, 2.11.1
  • Installation option (Docker install/Helm Chart): N/A
    • If Helm Chart, Kubernetes Cluster and version (RKE1, RKE2, k3s, EKS, etc):
  • Proxy/Cert Details: N/A

Information about the Cluster

  • Kubernetes version: Any
  • Cluster Type (Local/Downstream): Downstream
    • If downstream, what type of cluster? (Custom/Imported or specify provider for Hosted/Infrastructure Provider): Node-driver or custom RKE1

User Information

  • What is the role of the user logged in? Admin

Describe the bug

A user recently upgraded to Rancher version v2.10.5. After the upgrade, they rebooted one of the nodes in a downstream cluster. Following the reboot, the cattle-cluster-agent and cattle-node-agent pods are failing to start with the following error:

FailedMount 10s (x14 over 12m) kubelet MountVolume.SetUp failed for volume "cattle-credentials" : secret "cattle-credentials-b5a8ff3391" not found 

There was an update in logic to clean old cattle-credentials from downstream clusters that was introduced in Rancher v2.9.9, v2.10.5 and v2.11.1, cattle-credentials- secrets that are older than an hour, and whose name does not match the environment variable CATTLE_CREDENTIAL_NAME of the agent container, are deleted.

The issue is that the environment variable CATTLE_CREDENTIAL_NAME is not set on the cattle-node-agent DaemonSet. As a result, in Rancher-provisioned RKE1 clusters (where there is a cattle-node-agent DaemonSet), the in-use cattle-credentials-xxxxx secret is deleted by a cattle-node-agent Pod, once the credential is older than an hour.

To Reproduce

For freshly-provisioned RKE1 clusters in v2.10.5:

  • Provision a Rancher v2.10.5 setup
  • Provision a single-node RKE1 custom cluster
  • After an hour, observe an info message of the following format in the cattle-node-agent pod logs: time="2025-05-06T08:25:51Z" level=info msg="Deleting unused cattle-credentials secret: cattle-credentials-70fef9138d"
  • Delete a running cattle-cluster-agent or cattle-node-agent Pod

For existing clusters upon upgrade to v2.10.5:

  • Provision a Rancher v2.10.4 setup
  • Provision a single-node RKE1 custom cluster
  • Update Rancher to v2.10.5
  • After an hour (cattle-credentials- secret rotated during upgrade to v2.10.5), observe an info message of the following format in the node-agent Pod logs: time="2025-05-06T08:25:51Z" level=info msg="Deleting unused cattle-credentials secret: cattle-credentials-70fef9138d"
  • Delete a running cattle-cluster-agent or cattle-node-agent Pod

Result

In both cases, observe that the newly scheduled Pod fails to start with an error of the format: MountVolume.SetUp failed for volume "cattle-credentials": secret "cattle-credentials-70fef9138d" not found

Expected Result

New pods should run up successfully.

Screenshots

Image Image

Workaround: Manually recreate the deleted credential and recover a cluster to a working state, but it does not prevent future deletion and issue recurrence:

kubectl -n cattle-system create secret generic <cattle-credentials- secret name> --from-literal=namespace=<cluster-id> --from-literal=token=<system clusterregistration token for cluster> --from-literal=url=<rancher-url>

Where: <cattle-credentials- secret name> is the name of the missing cattle-credentials secret that can’t be mounted in agent pods, e.g. cattle-credentials-70fef9138d.

The customer will likely lose access to the Downstream cluster, so to find the cattle-credentials secret name, they are going to need to SSH into a node of the cluster, recover a kubeconfig and kubectl using the following KB: https://www.suse.com/support/kb/doc/?id=000020018 and run a command like the following “kubectl --kubeconfig kubeconfig_admin.yaml get pods -n cattle-system <cattle-cluster-agent-pod> -o yaml | grep -i cattle-credentials | head -1”

Alternatively, the secret name can be found as the value of the env var CATTLE_CREDENTIAL_NAME in the YAML output of the cattle-cluster-agent Deployment.

<cluster-id> is the cluster id of the affected rke1 cluster, e.g. c-hvrtq

<token> is the system clusterregistrationtoken of the affected RKE1 cluster retrieved from Rancher itself. Can be retrieved by navigating to <rancher-url>/v3/clusterRegistrationTokens/<cluster-id>:system whilst logged in as an admin user, and copying out the value from the token field

<rancher-url> is the rancher url, e.g. https://rancher.example.com/

SURE-10154

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 19 (9 by maintainers)

Most upvoted comments

@a2yp In my case, I executed the following commands on one of the cluster nodes, and it correctly generated the kubeconfig for me.

curl -O https://raw.githubusercontent.com/rancherlabs/support-tools/master/how-to-retrieve-kubeconfig-from-custom-cluster/rke-node-kubeconfig.sh

chmod +x rke-node-kubeconfig.sh

./rke-node-kubeconfig.sh

Then, with the link in hand, I was able to rebuild the secrets using the following command:

docker run --rm --net=host -v /root/kubeconfig_admin.yaml:/root/.kube/config --entrypoint bash rancher/rancher-agent:v2.11.1 -c ‘kubectl get secrets -n cattle-system’

docker run --rm --net=host -v /root/kubeconfig_admin.yaml:/root/.kube/config --entrypoint bash rancher/rancher-agent:v2.11.1 -c ‘kubectl create secret generic cattle-credentials-******* -n cattle-system --from-literal=url=https://rancher.******** --from-literal=token=************** --from-literal=namespace=c-******’

Here’s the reference link: https://www.suse.com/support/kb/doc/?id=000020018

Additional Workarounds

Since the root cause is that the cattle-node-agent performs cleanup every hour, possible workarounds include:

  • Restarting or recreating the cattle-node-agent pod every 50 minutes (or at any interval shorter than 60 minutes) to avoid triggering the cleanup.
  • Patching the cattle-node-agent to include the missing environment variable. However, this change is not persistent and will be reverted by Rancher when the cluster is updated, either by changing the configuration or by upgrading the Kubernetes version.

Hi @jiaqiluo , patching the cattle-node-agent to include the missing environment variable worked for me, thank you very much!