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 kubectl
Log in to your Azure account:
az login
If 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_NAME
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
This will update your ~/.kube/config
file with the cluster context.
List available contexts:
kubectl config get-contexts
Switch between contexts as needed:
kubectl config use-context CONTEXT_NAME
Check the nodes to ensure connectivity:
kubectl get nodes
Verify all pods and services across all namespaces:
kubectl get pods -A
kubectl get services -A
To list all AKS clusters across all resource groups:
az aks list --query '[].{name:name, resourceGroup:resourceGroup}' -o table
You might not have the necessary permissions to access the cluster. Check your Azure role assignments:
az aks show --resource-group myResourceGroup --name myAKSCluster
Ensure 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_NAME
Let me know if you need further assistance!