AKS – Azure Kubernetes Service is a managed service (PaaS) from Azure. We can provision Kubernetes clusters of any size in any region within few minutes using this service. This avoids the overhead of managing the infrastructure and we can focus more on the application development.

Here I am going to explain the steps to connect to an AKS from a Linux or Windows commandline.

The prerequisites are Azure Cli and kubectl.

The detailed steps to install Azure Cli on Windows and Linux are explained in the Microsoft Azure Documentation

The detailed steps to install kubectl are explained in Kubernetes documentation.

You can test the installation by typing az and kubectl commands in the command line.

Once we are ready with Azure Cli and kubectl, the next step is to authenticate with Azure. The command is given below.

az login

If you are executing the above command from a Windows machine, it will open up a page in the browser to authenticate yourself and to enter the security code to allow the command line login. If you are working on Linux without GUI, it will provide you a URL and code to enter. Screenshot of the same is given below.

Once the login is complete, we are ready for the next step. The above step is technically equivalent to an Azure account sign-in.

Within an azure account there can be multiple Azure Subscriptions. So the next step is to connect to a specific subscription within the logged-in azure account. The command is given below.

az account set --subscription [subscription-id]

Example command is given below

az account set –subscription 24edcfasdws-493f-4asdrfd-85f1-fc8asdfcdsdsdf

Once you are connected to the specific subscription, the next step is to connect to the AKS within the subscription. The command is given below.

az aks get-credentials --resource-group [resource-group-name] --name [aks-cluster-name] --admin

Example command is given below

az aks get-credentials –resource-group rg-my-aks –name my-aks-cluster –admin

This will generate the Kubernetes configuration file and saves it to our local configuration. Now we will be able to connect and interact with the Kubernetes cluster using the kubectl commands.

Now with this Kubernetes configuration, we will be able to interact with the AKS cluster without doing the first set of steps.

I hope this write up helps someone. If you have any questions, feel free to comment, I will respond.