How To Connect to an Azure Kubernetes Service (AKS) Cluster With Azure CLI and Kubectl

In this blog post, I will show you how to connect to an Azure Kubernetes Service (AKS) cluster using Azure CLI and run Kubectl commands.

Kubectl

In order to fully manage an AKS cluster and deploy applications and services, we need to utilise Kubectl which is the command-line tool for Kubernetes.

In an Azure deployment on AKS, we can access the kubectl command-line with Azure CLI and I will show you how to do it.

In this post, I am assuming that you have an AKS cluster running if you don’t visit these posts on how to deploy an AKS cluster with Terraform or ARM.

You also need to install Azure CLI on your Windows or macOS machine.

Connect and Install Kubectl

To connect to an Azure AKS cluster first we need to login to Azure using the following command:

az login

If you have more than one subscription set it using the following command:

az account set --subscription subname 

After login to Azure, install the Kubectl command line tools plug in for Azure CLI using the following line:

az aks install-cli

And finally, we run the following command to authenticate to our AKS cluster. Make sure you fill in the resource group name of your cluster and your cluster name:

az aks get-credentials --resource-group RGNAME --name CLUSTERNAME

From here you can type kubectl and access the help file and start managing your AKS cluster.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.