Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 7 of 28
❮Prev Next❯

Deploy to AKS with Manifest Files

Module 1: Containers ⏱ 10 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    On Azure Kubernetes Service (AKS) you describe your app in YAML manifest files and send them with kubectl apply -f. A Deployment says which image to run, how many replicas, which resources, probes and environment variables. A Service gives the pods a stable address (ClusterIP inside the cluster, LoadBalancer for a public IP). Kubernetes keeps the real state equal to what you declared, so a dead pod is replaced and a new image tag rolls out pod by pod.

    Simulate it » No Azure account needed

    Exam objective: 1.2.3 Deploy and manage applications to Azure Kubernetes Service (AKS) by using manifest files. (Skills measured as of October 7, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Apply a Deployment and a Service on AKS Apply a Deployment and a Service from YAML.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Open the cluster. Under <strong>Kubernetes resources</strong>, select <strong>Workloads</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open the cluster. Under Kubernetes resources, select Workloads.
    2. Only system workloads so far. Select + Create → Apply a YAML.
    3. The manifest asks for 3 replicas of the image and a LoadBalancer Service in front of them. Kubernetes keeps reality matching it.
    4. 3/3 ready. Open chat-api to see its pods.
    5. Now break something. Select one pod and Delete it.
    6. A new pod appears straight away. You never restart pods by hand; you declare how many you want.
    7. The Service got a public IP from Azure Load Balancer and spreads requests over all healthy pods.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    Someone changed a setting by hand on the cluster and nobody knows what.

    😊 THE SOLUTION

    Describe the app in YAML manifests and kubectl apply them.

    • Hand-made changes✓ Declarative YAML in git
    • A pod dies at 3 AM✓ The Deployment replaces it
    • Pods change IPs✓ A Service gives a stable name
    🛠️ Solved with: Kubernetes manifests

    Start with a question

    How do you tell 30 servers to run three copies of your API, and keep it that way?

    You could log in to each machine, start containers and restart them when they die. That’s fine for one server and miserable for thirty.

    On AKS, you write down what you want in a manifest: “three copies of ragapi:1.4.0, 0.5 CPU each, reachable on port 80”. You hand it to Kubernetes with kubectl apply, and Kubernetes keeps making it true.

    Explain it like I’m 10

    Visual: Kubernetes desired state in motion

    See a Deployment and Service go in with kubectl apply, then watch Kubernetes replace a dead pod and hold the line when an image is bad.

    ▶ Explainer video See it in motion 7 steps · 1 min 44 sec

    An animation of a YAML Deployment (3 replicas, image ragapi:1.4.0, readiness probe) and a LoadBalancer Service applied to an AKS cluster with kubectl apply; the controller starts three pods, replaces a pod that dies, and when a new image tag does not exist the new pod sits in ImagePullBackOff while the old pods keep serving, until the rollout is undone.
    Read the video script
    1. Write down what you wantOn AKS you don't start containers by hand. You write down what you want in a YAML manifest. This Deployment says: three copies of ragapi one point four, and here's the health check for each one.
    2. A Service gives one stable addressPods come and go, so callers need one address that doesn't change. That's the Service. It finds the pods by their label, and the LoadBalancer type gets a public IP from Azure.
    3. kubectl applyNow you hand it over with kubectl apply. Kubernetes places three pods on the nodes, each node pulls the image from your registry, and pods that pass the readiness probe join the Service.
    4. A loop keeps checkingAnd Kubernetes doesn't stop there. A controller keeps comparing what you asked for with what's really running. Right now they match, three and three, so it does nothing.
    5. A pod dies, a new one appearsNow a pod crashes. Ready drops to two, which doesn't match three. The controller notices and starts a replacement on its own. Nobody had to log in or restart anything.
    6. A bad image: ImagePullBackOffNext, someone changes the image to version one point five, but that tag was never pushed. The new pod can't pull it, so it shows ImagePullBackOff and keeps retrying. The rolling update waits, and the three old pods keep serving users.
    7. Undo, and you’re backTo fix it, roll back with kubectl rollout undo, or correct the tag in the YAML and apply it again. The broken pod is removed, and you're back to three healthy copies of the version that works.

    The technical explanation

    Cluster and access

    az aks create --resource-group rg-ai --name aks-rag \
      --node-count 2 --attach-acr myreg --generate-ssh-keys
    
    az aks get-credentials --resource-group rg-ai --name aks-rag
    kubectl get nodes

    --attach-acr assigns AcrPull to the cluster’s kubelet identity, so pods pull from myreg.azurecr.io without secrets. For an existing cluster: az aks update -n aks-rag -g rg-ai --attach-acr myreg.

    The manifest

    # ragapi.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ragapi
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: ragapi
      template:
        metadata:
          labels:
            app: ragapi            # must match the selector above
        spec:
          containers:
            - name: ragapi
              image: myreg.azurecr.io/ragapi:1.4.0
              ports:
                - containerPort: 8000
              env:
                - name: MODEL_DEPLOYMENT
                  value: gpt-4.1-mini
                - name: SEARCH_KEY
                  valueFrom:
                    secretKeyRef:
                      name: rag-secrets
                      key: search-key
              resources:
                requests: { cpu: 250m, memory: 512Mi }
                limits: { cpu: 500m, memory: 1Gi }
              readinessProbe:
                httpGet: { path: /healthz, port: 8000 }
              livenessProbe:
                httpGet: { path: /healthz, port: 8000 }
                initialDelaySeconds: 15
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: ragapi
    spec:
      type: LoadBalancer
      selector:
        app: ragapi
      ports:
        - port: 80
          targetPort: 8000

    The Service’s selector finds pods labelled app: ragapi. port is what callers use, targetPort is the container’s port. ClusterIP (the default) is reachable only inside the cluster; LoadBalancer asks Azure for a public IP on the cluster’s load balancer.

    Apply and check

    kubectl create secret generic rag-secrets --from-literal=search-key="$SEARCH_KEY"
    kubectl apply -f ragapi.yaml
    kubectl get deployments,pods,services
    kubectl get service ragapi --watch     # wait for EXTERNAL-IP

    Roll out a new version

    kubectl set image deployment/ragapi ragapi=myreg.azurecr.io/ragapi:1.5.0
    kubectl rollout status deployment/ragapi
    kubectl rollout undo deployment/ragapi     # if 1.5.0 misbehaves
    kubectl scale deployment/ragapi --replicas=5

    In a real pipeline you’d change the tag in the YAML and kubectl apply again, so the file in git always matches the cluster.

    1. 1 Declare

      kubectl apply sends the Deployment and Service to the API server.

    2. 2 Schedule

      The scheduler places 3 pods on nodes with room for their requests.

    3. 3 Pull and start

      Each node pulls the image from ACR and starts the container.

    4. 4 Ready

      Pods passing the readiness probe join the Service.

    What kubectl apply sets in motion
    Architect level Keeping secrets in Key Vault on AKS

    A Kubernetes Secret is only base64-encoded and sits in the cluster’s store. The Azure Key Vault provider for Secrets Store CSI Driver (az aks enable-addons --addons azure-keyvault-secrets-provider) mounts Key Vault secrets as files, and can sync them to a Kubernetes Secret if you need env vars. With Microsoft Entra Workload ID, the pod’s service account is federated with a managed identity that has access to the vault, so there’s no credential in the cluster at all. The same identity can call Azure OpenAI or Cosmos DB with DefaultAzureCredential.

    Real-world business scenario

    Media

    Proseware Media (fictional)

    The problem
    A recommendation API and three model-serving services ran on VMs with hand-written start scripts. A crashed process stayed down until someone noticed.
    What they used
    AKS with --attach-acr, a Deployment and Service manifest per service in git, readiness and liveness probes, and the Key Vault CSI driver for model keys.
    Why that choice
    Kubernetes replaces failed pods on its own, probes stop broken versions taking traffic, and the YAML in git is the record of what runs.
    The result
    Crashed pods restart in seconds, and releases are a reviewed change to a manifest.

    When to use it and when not to

    ✓ Use it when…

    • You need the Kubernetes API: custom controllers, operators, Helm charts or service meshes.
    • You need GPU node pools or fine control over nodes for model serving.
    • Many teams share one platform with namespaces and policies.

    ✕ Think twice when…

    • One or two APIs with no special Kubernetes needs; Container Apps is less to run.
    • Teams without time to own cluster upgrades, node patching and security.

    ↔ Alternatives to consider

    • Azure Container Apps for Kubernetes-style containers without managing a cluster.
    • AKS Automatic for a cluster with node management and best-practice settings handled for you.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AI-200 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    You need to make a Deployment in AKS reachable from the internet through a public IP address. Which Service type should you define in the manifest?

    Question 2

    Question 2 of 5

    After you apply a Deployment and a Service, the Service has no endpoints. The pods are running and ready. What is the most likely cause?

    Question 3

    Question 3 of 5

    Pods in an AKS cluster must pull images from the registry contosoacr without image pull secrets. Which command should you run?

    Question 4

    Question 4 of 5

    You update the image tag in a Deployment manifest and run kubectl apply. The new version causes errors. Which command should you run to return to the previous version?

    Question 5

    Question 5 of 5 · Select 2

    A Deployment manifest must provide an API key to a container as an environment variable. The key must not appear in the manifest. Which TWO approaches meet the requirement?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What's the difference between a Deployment and a Service?

    Model answer

    The Deployment runs the pods: image, replica count, resources. The Service is the front door: one stable address that forwards to whichever pods match its label selector. Pods come and go, the Service address stays.

    Intermediate How does AKS get permission to pull images from your ACR?

    Model answer

    I run az aks create or az aks update with --attach-acr myreg. That assigns AcrPull on the registry to the cluster's kubelet managed identity, so no imagePullSecrets are needed.

    Experienced developer How do you roll out a new image and roll back if it's bad?

    Model answer

    I change the image tag in the manifest and kubectl apply it, or use kubectl set image. The Deployment does a rolling update, replacing pods gradually and only counting new pods once their readiness probe passes. kubectl rollout status shows progress and kubectl rollout undo goes back to the previous ReplicaSet.

    Interviewer follows up

    Why do probes matter there?

    You

    Without a readiness probe, Kubernetes sends traffic to a pod as soon as the container starts, even if the model client isn't ready, and a broken version can roll out completely.

    Scenario The model endpoint key must reach the pods. Where do you put it?

    Model answer

    Not in the manifest or the image. A Kubernetes Secret at minimum, referenced with secretKeyRef. Better, the Secrets Store CSI Driver with the Azure Key Vault provider and workload identity, so the value stays in Key Vault.

    Quick revision

    Key points

    • az aks get-credentials writes kubeconfig so kubectl can talk to the cluster.
    • --attach-acr gives the kubelet identity AcrPull on the registry.
    • A Deployment declares image, replicas, resources, probes and env; its selector must match the pod template labels.
    • A Service selects pods by label; ClusterIP is internal, LoadBalancer gets an Azure public IP.
    • kubectl apply -f creates or updates; rollout status and rollout undo manage releases.

    Important terminology

    Manifest
    A YAML file that declares a Kubernetes object, such as a Deployment or Service, and its desired state.
    Deployment
    A Kubernetes object that keeps a set number of identical pods running and rolls out new versions.
    Pod
    The smallest unit Kubernetes runs; one or more containers that share a network address.
    Service
    A stable name and IP in front of a set of pods, selected by labels.
    kubectl apply
    The command that creates or updates objects so they match the manifest.
    Readiness probe
    A check that decides whether a pod receives traffic from its Service.

    Common mistakes

    • A Service selector that doesn't match the pod labels, so the Service has no endpoints.
    • Putting secrets as plain env values in the manifest and committing it.

    Exam tips

    • "Expose the app with a public IP" = Service type: LoadBalancer.
    • "Reachable only inside the cluster" = ClusterIP (the default).
    • "Pull from ACR without image pull secrets" = az aks update --attach-acr.

    Five quick revision questions

    1. 1.Which command sends a manifest to the cluster?Show

      kubectl apply -f ragapi.yaml

    2. 2.Which object keeps N copies of a pod running?Show

      A Deployment.

    3. 3.What is the default Service type?Show

      ClusterIP.

    4. 4.How do you roll back a Deployment?Show

      kubectl rollout undo deployment/ragapi

    5. 5.Which command gets AKS credentials for kubectl?Show

      az aks get-credentials

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Troubleshoot AKS and Container Apps: Logs, Events, Connectivity

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.