Creating Your First AKS Cluster

The best way to learn AKS is to actually build a cluster and deploy something to it. This page walks through every step: prerequisites, resource group setup, cluster creation, connecting kubectl, deploying a test application, and tearing everything down when you are done. By the end you will have run a real workload on Kubernetes in Azure.

Prerequisites

Before starting, make sure you have these installed:

  • Azure CLI — install from https://aka.ms/installazurecliwindows or via Homebrew on macOS
  • kubectl — the Kubernetes CLI, installable via az aks install-cli after logging in
  • An Azure subscription with permission to create resource groups and AKS clusters
# Verify Azure CLI is installed
az --version

# Log in to Azure
az login

# Install kubectl using the Azure CLI
az aks install-cli

# Verify kubectl is installed
kubectl version --client

If you are running in Azure Cloud Shell, both the Azure CLI and kubectl are already installed. Cloud Shell is the fastest way to follow along without installing anything locally.

Register required resource providers

Before creating AKS resources, the necessary Azure resource providers must be registered on your subscription. New subscriptions often do not have these registered yet.

az provider register --namespace Microsoft.ContainerService
az provider register --namespace Microsoft.Network
az provider register --namespace Microsoft.Storage
az provider register --namespace Microsoft.Compute

# Check registration status
az provider show --namespace Microsoft.ContainerService \
  --query "registrationState" -o tsv

Registration can take a few minutes. Wait until the status shows “Registered” before proceeding.

Step 1: Create a resource group

Everything in Azure lives inside a resource group. Create one for your AKS resources:

az group create \
  --name rg-aks-tutorial \
  --location eastus

Choose a region close to you or your users. East US and West Europe are common choices with broad VM availability.

Step 2: Create the AKS cluster

This command creates a minimal but complete AKS cluster. Each flag is explained below.

az aks create \
  --resource-group rg-aks-tutorial \
  --name aks-tutorial-cluster \
  --node-count 2 \
  --node-vm-size Standard_D2s_v3 \
  --enable-managed-identity \
  --enable-addons monitoring \
  --generate-ssh-keys \
  --location eastus

Flag breakdown:

  • —node-count 2 — start with 2 worker nodes. One is enough to experiment but 2 lets you see scheduling across nodes.
  • —node-vm-size Standard_D2s_v3 — 2 vCPUs, 8 GB RAM. Enough for most test workloads.
  • —enable-managed-identity — gives the cluster an Azure Managed Identity instead of a service principal. This is the modern, recommended approach.
  • —enable-addons monitoring — enables Azure Monitor Container Insights for logs and metrics.
  • —generate-ssh-keys — creates an SSH key pair for accessing nodes if needed.

Creation takes 5–10 minutes. Watch the output for any errors.

Note

AKS creates a second resource group automatically (named MC_rg-aks-tutorial_aks-tutorial-cluster_eastus by default) that holds the infrastructure resources: VMs, disks, load balancers, and networking. Do not manually delete resources from that group.

Step 3: Connect kubectl to your cluster

After the cluster is created, download credentials so kubectl can authenticate:

az aks get-credentials \
  --resource-group rg-aks-tutorial \
  --name aks-tutorial-cluster

This merges the cluster’s credentials into ~/.kube/config. Verify the connection:

# List nodes
kubectl get nodes

# Should output something like:
# NAME                                STATUS   ROLES   AGE   VERSION
# aks-nodepool1-12345678-vmss000000   Ready    agent   5m    v1.28.5
# aks-nodepool1-12345678-vmss000001   Ready    agent   5m    v1.28.5

Both nodes showing “Ready” means your cluster is healthy.

# Get basic cluster info
kubectl cluster-info

# View all system pods that AKS runs
kubectl get pods -n kube-system

Step 4: Deploy a test application

Deploy a simple nginx web server to verify your cluster can run workloads:

# Create a deployment
kubectl create deployment nginx-demo \
  --image=nginx:1.25 \
  --replicas=3

# Expose it with a LoadBalancer service
kubectl expose deployment nginx-demo \
  --port=80 \
  --target-port=80 \
  --type=LoadBalancer

Watch the service get its external IP (takes 1–2 minutes for Azure to provision the load balancer):

kubectl get service nginx-demo --watch

Once the EXTERNAL-IP column shows a real IP address (not “pending”), open it in a browser. You should see the nginx welcome page.

Step 5: Explore what Kubernetes created

Now that something is running, look around:

# See all running pods with their node assignments
kubectl get pods -o wide

# Describe the deployment
kubectl describe deployment nginx-demo

# See the replicaset that manages pods
kubectl get replicasets

# Look at pod logs
kubectl logs -l app=nginx-demo

# Scale to 5 replicas
kubectl scale deployment nginx-demo --replicas=5
kubectl get pods

When you scale to 5 replicas, Kubernetes creates 2 more pods and schedules them across your 2 nodes. Delete a pod manually and watch Kubernetes immediately create a replacement:

# Get a pod name
kubectl get pods

# Delete one (replace with your actual pod name)
kubectl delete pod nginx-demo-6d4f9b7c8d-abc12

# Watch it come back
kubectl get pods

Deploying from a YAML file

The kubectl create and expose commands are fine for learning, but real deployments use YAML files. Here is the YAML equivalent of what you just created:

# nginx-demo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-demo
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-demo
  template:
    metadata:
      labels:
        app: nginx-demo
    spec:
      containers:
      - name: nginx
        image: nginx:1.25
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: "100m"
            memory: "128Mi"
          limits:
            cpu: "250m"
            memory: "256Mi"
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-demo
spec:
  selector:
    app: nginx-demo
  ports:
  - port: 80
    targetPort: 80
  type: LoadBalancer
# Apply the YAML
kubectl apply -f nginx-demo.yaml

# Delete everything in the file
kubectl delete -f nginx-demo.yaml

Notice the resource requests and limits in the YAML. These are good practice and missing from the imperative kubectl commands. Always include them in real deployments.

Viewing the cluster in the Azure Portal

The Azure Portal provides a visual view of your cluster. Navigate to Kubernetes services in the portal and select your cluster. You can see:

  • Node status and resource utilization
  • Workloads (deployments, pods, replicasets)
  • Services and ingress
  • Metrics from Container Insights if you enabled monitoring

The portal also lets you connect to the cluster via a browser-based kubectl terminal without installing anything locally — useful for quick checks from any machine.

Cleaning up to avoid charges

AKS nodes are Azure VMs. They cost money while running even if no workloads are scheduled on them. When you are done experimenting, delete the cluster:

# Delete the entire resource group (deletes cluster and all associated resources)
az group delete \
  --name rg-aks-tutorial \
  --yes \
  --no-wait

The —no-wait flag returns immediately and deletion continues in the background. Use az group show —name rg-aks-tutorial to check when it is gone.

Tip

If you want to keep the cluster but stop paying for nodes temporarily, you can stop the cluster. This deallocates nodes but preserves the configuration: az aks stop —resource-group rg-aks-tutorial —name aks-tutorial-cluster

Common mistakes

  1. Forgetting to run az aks get-credentials. Creating a cluster does not automatically configure kubectl. Without this step, all kubectl commands fail with connection errors.
  2. Using kubectl delete to clean up test resources but leaving the cluster running. The nodes keep billing even with nothing scheduled on them. Always delete the cluster or the resource group when done.
  3. Not specifying resource requests in pod specs. Pods without resource requests are scheduled on a best-effort basis and can be evicted when nodes run low on memory. Always set requests.
  4. Deploying to the wrong cluster. If you have multiple clusters, verify your current context before applying changes: kubectl config current-context.
  5. Creating a cluster in a region without VM quota. New Azure subscriptions have low vCPU quotas per region. If cluster creation fails, check your quota in the Azure Portal under Subscriptions > Usage + quotas.

Frequently asked questions

How long does it take to create an AKS cluster?

Typically 5–10 minutes for a standard cluster. The control plane and node VMs need to be provisioned and joined together. Complex configurations with multiple node pools take longer.

What does az aks get-credentials do exactly?

It downloads the cluster credentials and merges them into your local kubeconfig file (~/.kube/config). After running it, kubectl knows how to authenticate with your AKS cluster.

How much does a minimal AKS cluster cost per month?

A single Standard_D2s_v3 node costs roughly $70/month in East US. A 3-node cluster runs around $210/month before storage and networking. You can reduce this with spot nodes or B-series burstable VMs for dev.

Last verified: 19 March 2026 Cloud services change frequently. Verify details against official documentation before making infrastructure decisions.