Skip to content

Connecting to AKS via Azure CLI

There are different ways to connect to Azure Kubernetes Cluster (AKS). This can be either done through Azure CLI or the Cloud shell directly from the Azure Portal. Firstly, let us see how to connect to an AKS cluster from Azure CLI installed on your Desktop

Prerequisites for accessing AKS via Azure CLI:

  • Azure CLI installed and configured on your machine
  • Contributor access to the target AKS cluster

Step-by-Step Guide for connecting to AKS using Azure CLI :

  1. Azure CLI Login:
    • Initiate the login process using az login --use-device-code. This will generate a unique code on your screen.
    • Open a separate web browser window and navigate to the provided URL. Enter the displayed code to authorize the sign-in.
    • Upon successful login, the Azure CLI will showcase a list of your available Azure subscriptions.

      This image has an empty alt attribute; its file name is image.png
  2. Set Subscription:
    • Designate the appropriate subscription you wish to utilize with the command az account set --subscription <your-subscription-name>. Replace <your-subscription-name> with the actual name of your target subscription.
      AKS Azure CLI
  3. Download Cluster Credentials:
    • Download the necessary cluster credentials using the following command: az aks get-credentials --resource-group <resource-group-name> --name <cluster-name>. Remember to substitute <resource-group-name> and <cluster-name> with the corresponding values for your specific AKS cluster.

      az login aks
  4. Kubelogin Authentication (if necessary):
    • In certain scenarios, you might encounter an error prompting the need for kubelogin. Kubelogin facilitates authentication with your Kubernetes cluster. You can find detailed installation instructions for kubelogin on the official Kubernetes documentation website.

By following these steps, you’ll be successfully connected to your AKS cluster via the Azure CLI. This empowers you to leverage the powerful kubectl command-line tool to manage your Kubernetes deployments within the AKS environment.