This guide will help you configure kubectl to access Azure Kubernetes Service (AKS) clusters, including setting up contexts and testing local configurations.
Make sure you have the following installed:
- Azure CLI (
az): To manage Azure resources. - kubectl: To interact with Kubernetes clusters.
# Install Azure CLI
brew install azure-cli
# Install kubectl
brew install kubectlLog in to your Azure account:
az loginIf you have multiple subscriptions, select the one you want to use:
az account set --subscription "YOUR_SUBSCRIPTION_NAME_OR_ID"Use the following command to add the AKS cluster context to your kubectl configuration:
az aks get-credentials --resource-group YOUR_RESOURCE_GROUP --name YOUR_AKS_CLUSTER_NAMEaz aks get-credentials --resource-group myResourceGroup --name myAKSClusterThis will update your ~/.kube/config file with the cluster context.
List available contexts:
kubectl config get-contextsSwitch between contexts as needed:
kubectl config use-context CONTEXT_NAMECheck the nodes to ensure connectivity:
kubectl get nodesVerify all pods and services across all namespaces:
kubectl get pods -A
kubectl get services -ATo list all AKS clusters across all resource groups:
az aks list --query '[].{name:name, resourceGroup:resourceGroup}' -o tableYou might not have the necessary permissions to access the cluster. Check your Azure role assignments:
az aks show --resource-group myResourceGroup --name myAKSClusterEnsure your service principal has the necessary roles:
- Azure Kubernetes Service Cluster Admin
- Azure Kubernetes Service Cluster User
If you have multiple clusters, you can switch contexts with:
kubectl config use-context CLUSTER_NAMELet me know if you need further assistance!