In this lab, you'll learn how to authenticate and connect to your Azure Kubernetes Service (AKS) cluster from your local terminal.
- kubectl installed on your local machine
- Access to an AKS cluster
- Authenticate and Connect to AKS
Run the following command to connect to AKS:
az aks get-credentials --resource-group devopsthehardway-rg --name devopsthehardwayaks --overwrite-existing
🔍 Note: Note: This command generates a kubeconfig file on your local machine with the necessary connection and authentication details.
- Verify Connection
Run the following command to confirm you're connected:
kubectl get nodes
To ensure you've successfully connected to your AKS cluster:
- The
kubectl get nodes
command should return a list of nodes without any errors. - You should be able to run other kubectl commands, such as
kubectl get pods --all-namespaces
.
After connecting to AKS, consider these questions:
- What is a
kubeconfig
file and why is it important? - How does the
az aks get-credentials
command facilitate cluster access? - What other kubectl commands can you use to verify your connection to the cluster?
Consider setting up different contexts in your kubeconfig file if you're working with multiple Kubernetes clusters. This allows you to switch between clusters easily using the kubectl config use-context
command.