Skip to main content
Version: 4

Connecting to AKS cluster

Before deploying the application, you need to connect to the target AKS cluster. This document provides a step-by-step procedure to authenticate with Azure, select the correct subscription, retrieve AKS cluster details, connect to the cluster, and configure kubeconfig for Azure CLI–based authentication.

Prerequisites​

  • Azure CLI installed

  • Kubectl installed

  • Kubelogin installed (required for exec-based authentication)

  • Appropriate access permissions (Reader/Contributor/AKS Cluster User Role)

Steps to connect to the AKS Cluster​

Perform the following steps on Windows Powershell:

  1. Authenticate with Azure using Azure CLI ​

    1. Run the following command:

      A browser window will open prompting you to sign in. 

    2. On the Sign in browser window, select Work or school account, and then click **Continue.

      **

    3. On the window that opens, enter the email id, phone number, or skype id for your Azure account, and then click Next.

      Once logged in, your available subscriptions will be displayed.

  2. Select the subscription​

    1. When prompted, type the corresponding number to select a subscription that you want to use, and then press Enter.
  3. Set the active subscription​

    1. Run the following command to set the subscription you selected in the previous step:

      This ensures all subsequent Azure CLI commands target the specified subscription.

  4. Retrieve AKS Cluster and Resource Group information​

    1. Run the following command to get all AKS cluster names and their resource groups for the specific Azure subscription ID.

    2. From the output, note down the name of the Cluster you want to connect to and its and Resource Group.

  5. Connect to the AKS Cluster​

    1. Use the following command to download kubeconfig credentials and merge them into your local kubeconfig file:

      The --overwrite-existing parameter ensures any previous configurations for this cluster are replaced with updated credentials.

  6. Verify the connection​

    1. Check the current Kubernetes context to confirm that kubectl is pointed to the correct cluster:

      Expected output:
      Name of the AKS Cluster.

  7. Convert Kubeconfig to use Azure CLI authentication​

    1. Run the following command to convert your kubeconfig to use Azure CLI tokens instead of deprecated AAD auth:


      *
      This updates your kubeconfig so kubectl authenticates using the Azure CLI login session (*az login*), improving reliability and compatibility with current AKS authentication requirements.*

  8. Go back to this document to deploy the application on the Cluster you connected to.