How To Connect to an Azure Kubernetes Service (AKS) Cluster With Azure CLI and Kubectl
Table of contents
In this blog, I will help you access the AKS cluster from your local machine by using the Azure-CLI and Kubectl command.
Prerequisites
It will be good if you have a basic understanding of Azure and Kubernetes, below tool is needed before we processed with installation:
Basic Azure CLI as it will help you in managing the azure resources more easily. You need to install the Azure CLI if it is not installed already from the official doc learn.microsoft.com/en-us/cli/azure/install.. as per your local Window or MacOS machine.
Understanding basic Kubectl commands-line-tool will help to manage the cluster. You can install the kubectl from the official Kubernetes doc https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/ Installation and configuration steps
Installation and Configuration Steps
Once both command-line-tool installations are completed, you can log in to your azure account from your local machine by running the below command as it will be needed to connect to the AKS cluster.
az login
check if your cluster is in the same subscription or not, by running the below command az:
account show
If you have more than one subscription then run the below command to set/change the subscription where your cluster is running:
az account set --subscription "subscription-name"
once you are connected to the subscription, the next step is to connect to the AKS cluster within the subscription which is set by using the previous command.
we run the following command to authenticate to our AKS cluster. Make sure you update the resource group name and cluster name:
az aks get-credentials --resource-group "resource-group-name" --name "aks-cluster-name"
Finally, we will be able to connect and manage the AKS cluster by using the Kubectl commands.
I hope this blog helps you and if you have any suggestions/questions, feel free to comment.