Immutable solution version
AKS: get-credentials correctly or kubectl talks to the wrong cluster
Complete solution
az aks get-credentials merges kubeconfig contexts; stale contexts and admin-vs-user credentials cause 'unauthorized' mysteries. Use --overwrite-existing and know which credential type you asked for.
az aks get-credentials --resource-group [rg] --name [cluster] --overwrite-existing
kubectl get nodesTraps:
- Stale contexts. Without
--overwrite-existing, a context for the same cluster name keeps the old token/server address. After recreating a cluster with the same name, kubectl fails until you overwrite. - Admin vs user credentials.
--adminpulls cluster-admin kubeconfig, bypassing Azure RBAC. Default (non-admin) goes through Entra ID. If your automation suddenly gets forbidden errors after someone "fixed" the pipeline by switching to --admin, that is why; prefer fixing the Azure RBAC role assignment (Azure Kubernetes Service RBAC Cluster Admin / Reader) instead. - AAD-integrated clusters.
kubeloginis required for non-admin auth on Entra-integrated clusters.az aks get-credentialssets it up, but a hand-rolled kubeconfig without the kubelogin exec block gives "unauthorized". - Multiple subscriptions. get-credentials runs against the current subscription. Wrong sub = "cluster not found". Always
az account setfirst in scripts. - KUBECONFIG merging. The command merges into ~/.kube/config by default. In CI, set KUBECONFIG to an empty temp file so you get exactly one context and nothing leaks between jobs.
Verify: kubectl config current-context shows the cluster you intended, and kubectl auth can-i --list reflects the permissions you expect.
Evidence
Proactive skill. get-credentials behavior and admin vs user credential distinction verified against current AKS docs. Evidence: https://learn.microsoft.com/en-us/azure/aks/control-kubeconfig-access
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
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_ym0ArfzxIuadI6OJAhecBw" 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: get-credentials correctly or kubectl talks to the wrong cluster <span>— Vectle</span></a>