Azure Kubernetes Service (AKS) simplifies the deployment, management, and scaling of containerized applications using Kubernetes. To interact with an AKS cluster, you need to establish a connection using kubectl, the Kubernetes command-line tool. This guide provides a step-by-step process to explain How To Connect Azure Kubernetes Cluster Using Kubectl
Why Kubectl needed?Connecting to an AKS cluster is an essential step for managing workloads, monitoring performance, and deploying applications. This process is especially critical for:
\ Whether you’re a developer or administrator, establishing this connection ensures you can effectively manage your Kubernetes environment.
\ To connect to an Azure Kubernetes Service (AKS) cluster using kubectl, you will need to perform the following steps:
Prerequisites (install both Azure CLI and Kubectl) STEP: 1 Install the Azure CLIIf you haven’t installed the Azure CLI on your local machine, you can download and install it from the official Microsoft documentation here.
STEP: 2 Install KubectlInstall the Kubernetes command-line (click here) tool “Kubectl” , if you haven’t installed it already.
Steps to connect Azure account: STEP: 3 Authenticate with AzureOpen command prompt, run az login command to authenticate your CLI with your Azure account. Once you run this command, you will be prompted to enter your Azure account credentials.
az login Steps to connect Azure AKS Cluster:Go to Azure Portal -> Kubernetes Services -> Select the required Cluster -> Overview -> Connect -> to find the entire command for the specific cluster itself or follow the below commands one by one by replacing with subscription Id, cluster name and resource group name.
STEP: 4 Set the subscriptionTo set subscription, run
az account set --subscriptiond 95fe7-8d2c-4297-ad8b-a8eb08322955 STEP: 5 Generate kubeconfig fileOpen command prompt, run the below command and run az aks get-credentials command to connect to your AKS cluster. The get-credentials command downloads credentials and configures the Kubernetes CLI to use them.
\
#Syntax: az aks get-credentials --resource-group\ Replace with the name of the resource group that contains your AKS cluster, and with the name of your AKS cluster.
az aks get-credentials --resource-group rg-dgtl-pprd-we-01 --name aks-dgtl-pprd-we-01\ Above command will create the kubeconfig file in the user root directory. To get kubeconfig file in the specific location
Connect Azure Kubernetes Cluster Using Kubectl STEP: 6 Verify the connectionTo verify that Kubectl is connected to your AKS cluster, run the Kubectl get nodes command. This command should display a list of the nodes in your AKS cluster. If the command returns the list of nodes, then you have successfully connected to your AKS cluster using Kubectl.
kubectl get nodes Points to RememberConnecting to an AKS cluster using kubectl is a fundamental skill for managing Kubernetes workloads in Azure. By following this guide, you can authenticate, configure, and verify your connection to the AKS cluster seamlessly. This enables you to monitor cluster performance, deploy applications, and manage resources effectively. As Kubernetes continues to be a vital platform for container orchestration, mastering tools like kubectl and Azure CLI is essential for efficient cluster management.
All Rights Reserved. Copyright 2025, Central Coast Communications, Inc.