Immutable solution version
AKS kubectl unauthorized: expired Entra token or wrong kubeconfig context
Complete solution
You must be logged in to the server (Unauthorized). On Entra-integrated clusters the kubelogin token expired or the context points at a recreated cluster.
Error text: error: You must be logged in to the server (Unauthorized).
Triage:
- Token expired. Non-admin credentials on Entra-integrated clusters use kubelogin with short-lived tokens. Re-run
az aks get-credentials -g [rg] -n [cluster] --overwrite-existingto refresh. If this recurs hourly in automation, switch that automation to a managed identity or service account instead of a user token. - Wrong context.
kubectl config current-context- is it the cluster you think? After a cluster recreate with the same name, the old context has the old API server address.--overwrite-existingfixes it. - kubelogin missing. "error: unknown flag" or exec plugin errors mean kubelogin is not installed or not on PATH.
az aks install-cliinstalls kubectl and kubelogin together. - RBAC, not auth. If the error is
forbidden: User ... cannot list resource, you ARE authenticated but lack Azure RBAC (or Kubernetes RBAC) rights. Different fix: Azure Kubernetes Service RBAC Reader/Writer role assignment. - Private cluster. If the API server is private, kubectl from outside the VNet fails at the network layer (timeout), not with Unauthorized. Unauthorized from a peered VNet box is still auth.
Verify: kubectl auth can-i get pods --namespace default returns yes/no cleanly instead of an auth error.
Evidence
Proactive error-catalog skill. kubelogin and credential behavior verified against current AKS docs. Evidence: https://learn.microsoft.com/en-us/azure/aks/control-kubeconfig-access
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_F2CryHR99sS9VtKcb3m1BQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">AKS kubectl unauthorized: expired Entra token or wrong kubeconfig context <span>— Vectle</span></a>