rancher: Fail to provision AKS private cluster: "error generating service account"

Rancher Server Setup

  • Rancher version: 2.7.5-rc1
  • Installation option: Helm
    • If Helm Chart, Kubernetes Cluster and version: AKS with Kubernetes v1.25.5

Information about the Cluster

  • Kubernetes version: v1.25.5
  • Cluster Type: AKS cluster

User Information

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

Describe the bug This issue was found during validation of version 2.7.5-rc1.

A similar, very detailed, issue was reported last year rancher/rancher#37164 but looks like this is still happening.

Provisioning a private AKS cluster (selecting the ‘Enable Private Cluster’) successfully creates the required resources in Azure but, after running the registration command in the provisioned cluster, it fails to establish connection between Rancher and AKS.

To enable communication with the private cluster, cluster agent opens a tunnel to connect the managed cluster with Rancher. For some unknown reason the tunnel is not providing the expected connectivity.

To Reproduce

  • Using Rancher UI, provision a new AKS cluster
  • Configure the cluster to be private: Networking Options -> Show advanced options -> Enable Private Cluster
  • Connect to the AKS cluster and apply the registration command provided by Rancher: via a bastion VM or using az aks command invoke --resource-group <rg> --name <cluster> --command "kubectl <command>"

Result The cluster gets stuck in Waiting state with error:

Failed to communicate with cluster: error generating service account token:

Logs from aks-operator and cattle-cluster-agent apparently do not contain errors.

Expected Result Investigate this issue to understand how the tunnel works and what’s causing the connectivity error.

Ideally, the cluster agent connection between Rancher and managed cluster is established and the cluster appears as Active in the UI.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (19 by maintainers)

Most upvoted comments

It seems hostname of AKS private cluster exceeding 100 char limit caused this failure. Using this theory I was also able to reproduce this issue in the eastus region, where previously I was able to successfully provision a private cluster.

Great job on finding the cause and fixing it @rohitsakala 🎉

@rohitsakala I tested on v2.11-7b3687b2e6fc130b8931e5b4eed28180cc5e3e2a-head. eastus works well, but I was able to reproduce in centralindia, consistently; even with system-store.

failed to communicate with cluster: error generating service account token: Get "https://pvala-aks-dns-zz1yy1j3.105098f4-4e55-494b-bf15-fe43ee0719cf.privatelink.centralindia.azmk8s.io:443/api/v1/namespaces/cattle-system": net/http: TLS handshake timeout

Will this issue be backported to 2.11?

No

We could reproduce this issue on v2.11-head today with @valaparthvi. We observed that sometimes the cluster-agent on Private AKS cluster in unable to initiate the wss connection to rancher so rancher is keep trying to do a direct api call to the AKS cluster which fails:

Failed to communicate with cluster: error generating service account token: Get "https://th-dns-india-6cblk0gt.25722f71-570a-4a3e-b9eb-2c2b38468b28.privatelink.centralindia.azmk8s.io:443/api/v1/namespaces/cattle-system": net/http: TLS handshake timeout

From the cluster-agent logs on AKS it seems the wss reverse tunnel is probably not initiated although its pod is Running. The logs are stuck on Connecting to ....

INFO: Value from https://1.2.3.4.nip.io/v3/settings/cacerts is an x509 certificate
time="2025-05-16T14:25:03Z" level=info msg="Listening on /tmp/log.sock"
time="2025-05-16T14:25:03Z" level=info msg="Rancher agent version v2.11-87f9ae2722bbb03618ab00a99bb3b6ced6cfaf61-head is starting"
time="2025-05-16T14:25:03Z" level=info msg="EnsureSecretForServiceAccount: waiting for secret [cattle-system:cattle-token-lc4nj] for service account [cattle-system:cattle] to be populated with token"
time="2025-05-16T14:25:03Z" level=info msg="EnsureSecretForServiceAccount: got the service account token for service account [cattle-system:cattle] in 22.553472ms"
time="2025-05-16T14:25:03Z" level=info msg="Testing connection to https://1.2.3.4.nip.io using trusted certificate authorities within: /etc/kubernetes/ssl/certs/serverca"
time="2025-05-16T14:25:03Z" level=info msg="Connecting to wss://1.2.3.4.nip.io/v3/connect/register with token starting with 75f47ltcg2s6dp6gtcf6sbppxwx"
time="2025-05-16T14:25:03Z" level=info msg="Connecting to proxy" url="wss://1.2.3.4.nip.io/v3/connect/register"
time="2025-05-16T14:29:45Z" level=error msg="Remotedialer proxy error" error="websocket: close 1006 (abnormal closure): unexpected EOF"
time="2025-05-16T14:29:45Z" level=warning msg="[12] encountered error \"use of closed network connection\" while writing error \"dial tcp 10.224.0.4:44: operation was canceled\" to close remotedialer"
time="2025-05-16T14:29:55Z" level=info msg="Connecting to wss://1.2.3.4.nip.io/v3/connect with token starting with 75f47ltcg2s6dp6gtcf6sbppxwx"
time="2025-05-16T14:29:55Z" level=info msg="Connecting to proxy" url="wss://1.2.3.4.nip.io/v3/connect"

Interesting is that for some regions like canadacentral it’s working fine but “sometimes” it doesn’t work from centralindia region (both tried on the same local rancher cluster). We did not touch tls-mode settings in rancher.

The error message:

Failed to communicate with cluster: error generating service account token: Post "https://aks-dns-europe-dgrigorev-<...>.privatelink.westeurope.azmk8s.io:443/api/v1/namespaces": dial tcp: address aks-dns-europe-dgrigorev-<...>.privatelink

is appearing in some cases. There is a race condition somewhere, preventing agent setup. To understand what is wrong at least the size of the remotedialer error messages should be increased. Right now it is trimmed to 100 bytes as per https://github.com/rancher/remotedialer/blob/0018e88e72de6eb8714acab029ea01376d4678e2/message.go#L180C54-L180C54. Is it dial tcp too many colons in address?.. Simply can’t say. Some private clusters come up normally and experience no issues with connectivity. Potential areas of the issue - networking, remotedialer setup.