Skip to content
Latchkey

az aks get-credentials: AKS kubeconfig in CI

Merge AKS cluster credentials into kubeconfig so kubectl and helm can target the cluster.

az aks get-credentials downloads kubeconfig entries for an AKS cluster and merges them locally. In CI it follows az login and precedes any kubectl or helm step. For AAD-enabled clusters you may also need kubelogin on the runner.

Common flags

  • -n NAME and -g RESOURCE_GROUP - target cluster
  • --admin - fetch cluster-admin credentials (bypasses AAD)
  • --overwrite-existing - replace stale entries in kubeconfig

Example in CI

Fetch credentials, then confirm kubectl connectivity.

shell
az aks get-credentials -g my-rg -n my-cluster --overwrite-existing
kubectl get nodes

Common errors in CI

  • ResourceNotFound: ... managedCluster ... not found - wrong cluster name or resource group
  • kubelogin: command not found - AAD cluster needs kubelogin installed on the runner
  • error: You must be logged in to the server (Unauthorized) - SP lacks an Azure Kubernetes Service RBAC role

Key takeaways

  • Merges AKS credentials into kubeconfig for kubectl and helm.
  • AAD-enabled clusters require kubelogin on the runner.
  • Use --overwrite-existing to avoid stale kubeconfig entries in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →