Azure Documentation

Create an Azure Kubernetes Service (AKS) Cluster

This tutorial guides you through the process of creating a fully functional Azure Kubernetes Service (AKS) cluster using the Azure CLI. AKS simplifies deploying, managing, and automating Kubernetes applications.

Prerequisites

Step 1: Sign in to Azure

Log in to your Azure account using the Azure CLI:

az login

This command opens a browser window for you to authenticate. After successful authentication, the CLI will display your account information.

Step 2: Create a Resource Group

A resource group is a logical container for your Azure resources. Create a resource group named myAKSResourceGroup in the eastus region:

az group create --name myAKSResourceGroup --location eastus

Step 3: Create an AKS Cluster

Create an AKS cluster named myAKSCluster. This command deploys a cluster with two agent nodes. The creation process can take several minutes.

az aks create --resource-group myAKSResourceGroup --name myAKSCluster --node-count 2 --enable-addons monitoring --generate-ssh-keys

--node-count specifies the number of agent nodes in the Kubernetes agent pool.

--enable-addons monitoring includes the Azure Monitor for containers add-on.

--generate-ssh-keys automatically generates SSH public and private key files for secure access to the cluster nodes.

Note

You can customize the cluster configuration further by specifying parameters like Kubernetes version, VM size, and networking options. Refer to the az aks create command reference for all available options.

Step 4: Get AKS Cluster Credentials

To connect to your AKS cluster, you need to download its Kubernetes configuration file and set the KUBECONFIG environment variable. The following command downloads the credentials:

az aks get-credentials --resource-group myAKSResourceGroup --name myAKSCluster

This command merges the Kubernetes configuration for your AKS cluster into your local ~/.kube/config file.

Step 5: Verify Cluster Connection

Verify that the cluster can be accessed using kubectl. You should get a list of nodes in your cluster.

kubectl get nodes

The output will list the agent nodes that were created in the previous steps.

Important

Keep your cluster credentials secure. Treat the downloaded ~/.kube/config file with the same care as you would any sensitive credential.

Next Steps

Congratulations! You have successfully created an Azure Kubernetes Service (AKS) cluster. Now you can: