How To Connect to an 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

To fully manage an AKS cluster and deploy applications and services, we must utilise Kubectl, 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 assume you have an AKS cluster running if you don’t visit these posts on deploying an AKS cluster with Terraform or ARM.

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

How To Connect to an AKS Cluster With Azure CLI and Kubectl

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

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:

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:

You can type kubectl, access the help file, and start managing your AKS cluster.

Processing…
Success! You're on the list.