0
0
KubernetesHow-ToBeginner · 3 min read

How to Create an AKS Cluster in Kubernetes Quickly

To create an AKS cluster, use the Azure CLI command az aks create with your resource group and cluster name. After creation, connect to the cluster using az aks get-credentials to manage it with kubectl.
📐

Syntax

The main command to create an AKS cluster is az aks create. You specify the resource group, cluster name, and node count. Then use az aks get-credentials to configure your local kubectl to connect to the cluster.

  • az aks create: Creates the AKS cluster.
  • --resource-group: The Azure resource group name.
  • --name: The name of your AKS cluster.
  • --node-count: Number of nodes in the cluster.
  • az aks get-credentials: Downloads cluster config for kubectl.
bash
az aks create --resource-group <resource-group> --name <cluster-name> --node-count <number> --generate-ssh-keys
az aks get-credentials --resource-group <resource-group> --name <cluster-name>
💻

Example

This example creates an AKS cluster named myAKSCluster in the resource group myResourceGroup with 3 nodes. Then it configures kubectl to connect to the cluster.

bash
az group create --name myResourceGroup --location eastus
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --generate-ssh-keys
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
kubectl get nodes
Output
NAME STATUS ROLES AGE VERSION aks-nodepool1-12345678-vmss000000 Ready agent 5m v1.26.1 aks-nodepool1-12345678-vmss000001 Ready agent 5m v1.26.1 aks-nodepool1-12345678-vmss000002 Ready agent 5m v1.26.1
⚠️

Common Pitfalls

Common mistakes when creating AKS clusters include:

  • Not creating or specifying the Azure resource group before cluster creation.
  • Forgetting to generate SSH keys or provide them, which is required for node access.
  • Not running az aks get-credentials after creation, so kubectl cannot connect.
  • Using an unsupported Azure region or insufficient permissions.

Always verify your Azure CLI is logged in and updated.

bash
## Wrong: Missing resource group
az aks create --name myAKSCluster --node-count 3 --generate-ssh-keys

## Right: Create resource group first
az group create --name myResourceGroup --location eastus
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --generate-ssh-keys
📊

Quick Reference

CommandDescription
az group create --name --location Create an Azure resource group
az aks create --resource-group --name --node-count --generate-ssh-keysCreate AKS cluster with nodes and SSH keys
az aks get-credentials --resource-group --name Download cluster config for kubectl
kubectl get nodesList nodes in the AKS cluster

Key Takeaways

Always create an Azure resource group before creating an AKS cluster.
Use az aks create with --generate-ssh-keys to set up node access easily.
Run az aks get-credentials to configure kubectl for cluster management.
Verify Azure CLI login and permissions before creating the cluster.
Check node status with kubectl get nodes after cluster creation.