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:
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
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
You can type kubectl, access the help file, and start managing your AKS cluster.
Related Articles
- Deploy an Azure Kubernetes Service (AKS) Cluster With Terraform
- Azure Kubernetes Service (AKS) is Now Generally Available
- Get All Resources Running On Kubernetes Using a Single Command
- Deploy a Basic Application to Azure AKS
- Deploy an Azure Kubernetes Service (AKS) Cluster With Terraform