Overview and What You Will Learn
In this lab, you will build a container image, push it to Azure Container Registry, create an AKS cluster wired to that registry, and deploy the container so it's reachable through a load-balanced public endpoint - the complete path from source code to a running, accessible service.
Why This Matters in Production
A team at Hotstar running several interdependent containerized services - a recommendation engine, a video metadata service, a user profile service - needs coordinated scaling, service discovery, and self-healing across all of them simultaneously. AKS provides exactly this orchestration layer, handling failures and scaling decisions that would otherwise require significant manual coordination across separate containers running independently.
Core Principles
The path from source code to a running AKS workload passes through three distinct stages.
+------------------------------------------+| Container image built locally or in CI |+------------------------------------------+ | v+------------------------------------------+| Pushed to Azure Container Registry (ACR) |+------------------------------------------+ | v+------------------------------------------+| AKS cluster pulls the image from ACR || and runs it as a Pod, exposed via a || Kubernetes Service and Load Balancer |+------------------------------------------+Attaching ACR directly to the AKS cluster at creation time means the cluster's nodes are automatically granted permission to pull images from that registry, with no separate credential configuration needed.
Detailed Step-by-Step Practical Lab
- Create a Resource Group and an Azure Container Registry:
az group create --name rg-aks-lab-mumbai --location centralindia az acr create \ --resource-group rg-aks-lab-mumbai \ --name acraakslabrahul \ --sku Basic- Build a container image directly in ACR, with no local Docker installation required:
az acr build \ --registry acraakslabrahul \ --image cart-service:v1 .- Create an AKS cluster, attaching the registry so nodes can pull images from it automatically:
az aks create \ --resource-group rg-aks-lab-mumbai \ --name aks-lab-mumbai \ --node-count 2 \ --attach-acr acraakslabrahul \ --generate-ssh-keys- Retrieve the cluster's credentials so
kubectlcan connect to it:
az aks get-credentials \ --resource-group rg-aks-lab-mumbai \ --name aks-lab-mumbai- Deploy the container image as a Kubernetes Deployment:
kubectl create deployment cart-service \ --image=acraakslabrahul.azurecr.io/cart-service:v1- Expose the deployment through a Kubernetes Service backed by an Azure Load Balancer, making it reachable from outside the cluster:
kubectl expose deployment cart-service \ --type=LoadBalancer \ --port=80 \ --target-port=8080- Wait for the Load Balancer to receive a public IP, then confirm the service is reachable:
kubectl get service cart-service --watch## Wait until EXTERNAL-IP shows an actual IP instead of <pending>- Confirm the pod is running correctly:
kubectl get pods- Clean up:
az group delete --name rg-aks-lab-mumbai --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakeManually managing ACR credentials as Kubernetes secrets instead of using
--attach-acrat cluster creation. Manual credential management means those credentials can expire or be misconfigured, causing confusing image pull failures - attaching the registry directly grants pull access through the cluster's own managed identity instead.
TipUse
kubectl describe pod <pod-name>immediately when a pod does not reach a Running state. It shows the exact reason - an image pull failure, insufficient node resources, or a failed readiness check - rather than requiring you to guess.
- Reach for AKS specifically once you have multiple interdependent containerized services, not for a single simple container that Azure Container Instances could run with far less operational overhead.
- Node count and VM size directly determine cluster capacity and cost. Start with a small node count for a lab or early-stage workload, and use the Cluster Autoscaler once real production traffic patterns are understood.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az acr build |
Build a container image directly inside ACR |
az aks create --attach-acr |
Create an AKS cluster with registry access pre-configured |
az aks get-credentials |
Configure kubectl to connect to the cluster |
kubectl describe pod <name> |
Diagnose why a pod isn't reaching Running state |