0
0
Azurecloud~5 mins

AKS cluster creation in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Creating an AKS cluster lets you run and manage containerized apps on Azure easily. It solves the problem of setting up and managing Kubernetes infrastructure by automating it for you.
When you want to deploy a scalable web app using containers on Azure.
When you need to run multiple microservices that communicate with each other.
When you want to test Kubernetes workloads without managing the underlying servers.
When you want to use Azure's managed Kubernetes service to reduce operational overhead.
When you want to integrate your container apps with Azure DevOps pipelines.
Commands
This command creates a resource group in Azure to hold your AKS cluster and related resources.
Terminal
az group create --name example-resource-group --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resource-group", "location": "eastus", "managedBy": null, "name": "example-resource-group", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Specifies the name of the resource group.
--location - Specifies the Azure region where resources will be created.
This command creates the AKS cluster with 2 nodes, enables managed identity for security, and generates SSH keys for node access.
Terminal
az aks create --resource-group example-resource-group --name example-aks-cluster --node-count 2 --enable-managed-identity --generate-ssh-keys
Expected OutputExpected
{ "aadProfile": null, "agentPoolProfiles": [ { "count": 2, "maxPods": 110, "name": "nodepool1", "osType": "Linux", "type": "VirtualMachineScaleSets", "vmSize": "Standard_DS2_v2" } ], "fqdn": "example-aks-cluster-12345.hcp.eastus.azmk8s.io", "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resource-group/providers/Microsoft.ContainerService/managedClusters/example-aks-cluster", "location": "eastus", "name": "example-aks-cluster", "nodeResourceGroup": "MC_example-resource-group_example-aks-cluster_eastus", "provisioningState": "Succeeded", "resourceGroup": "example-resource-group", "sku": { "name": "Basic", "tier": "Free" }, "type": "Microsoft.ContainerService/ManagedClusters" }
--resource-group - Specifies the resource group where the cluster will be created.
--name - Names the AKS cluster.
--node-count - Sets the number of nodes in the cluster.
--enable-managed-identity - Enables Azure managed identity for the cluster.
--generate-ssh-keys - Automatically creates SSH keys for node access.
This command downloads the cluster credentials and configures kubectl to connect to your AKS cluster.
Terminal
az aks get-credentials --resource-group example-resource-group --name example-aks-cluster
Expected OutputExpected
Merged "example-aks-cluster" as current context in /home/user/.kube/config
--resource-group - Specifies the resource group of the AKS cluster.
--name - Specifies the name of the AKS cluster.
This command lists the nodes in your AKS cluster to verify it is running and ready.
Terminal
kubectl get nodes
Expected OutputExpected
NAME STATUS ROLES AGE VERSION aks-nodepool1-12345678-vmss000000 Ready agent 2m v1.26.1
Key Concept

If you remember nothing else from this pattern, remember: creating an AKS cluster involves making a resource group, creating the cluster with nodes, then connecting kubectl to manage it.

Common Mistakes
Not creating a resource group before creating the AKS cluster.
The AKS cluster needs a resource group to hold its resources; without it, creation fails.
Always run 'az group create' first to make the resource group.
Skipping the 'az aks get-credentials' step before using kubectl.
kubectl won't know how to connect to the cluster without the credentials configured.
Run 'az aks get-credentials' to download and set up access.
Using too few nodes for workload needs or skipping SSH key generation.
Too few nodes can cause performance issues; missing SSH keys make node access harder.
Specify a suitable node count and use '--generate-ssh-keys' for easy access.
Summary
Create a resource group to hold your AKS cluster resources.
Create the AKS cluster with a specified node count and managed identity.
Download cluster credentials to configure kubectl access.
Verify the cluster nodes are ready using kubectl.