Deploying and Updating Applications on AKS
This lesson explains declarative deployment with kubectl apply, rolling updates, rollbacks and ways to manage manifests for several environments.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how kubectl apply reconciles objects.
- Explain how rolling updates and readiness probes interact.
- Describe how to roll back a Deployment.
- Compare Kustomize, Helm and pipeline substitution.
Declarative deployment with kubectl apply
kubectl apply -f FILE sends the objects in a manifest to the API server. If an object does not exist, it is created; if it exists, Kubernetes updates it to match the file. Running the same command again with an unchanged file changes nothing, which makes apply idempotent and suitable for pipelines. A folder of manifests can be applied with kubectl apply -f k8s/.
kubectl create namespace orders
kubectl apply -f k8s/
kubectl get deployments,services,pods -n orders
kubectl diff -f k8s/kubectl diff shows what applying a file would change, which is useful in a review step. Imperative commands such as kubectl create deployment or kubectl set image are convenient for experiments but leave the files out of date, so teams that keep manifests in source control apply changes through the files.
Declarative or imperative?
Rolling updates
Changing a Deployment's Pod template, typically the image tag, starts a rolling update. The Deployment creates a new ReplicaSet and shifts Pods from the old one to the new one gradually, so the application keeps serving. Two settings in the default RollingUpdate strategy control the pace: maxSurge, how many Pods above the desired count may exist during the update, and maxUnavailable, how many may be unavailable; both default to 25%.
-
Edit and apply
Change the image tag in the manifest and run kubectl apply.
-
Create new Pods
The new ReplicaSet starts Pods with the new image, up to the surge limit.
-
Wait for readiness
Each new Pod must pass its readiness probe before it receives traffic.
-
Retire old Pods
Old Pods are terminated as new ones become ready, within the unavailability limit.
Readiness probes are what make rolling updates safe. If new Pods never become ready, for example because the new image fails its health check, the rollout stalls with old Pods still serving, instead of replacing a working version with a broken one. kubectl rollout status deployment/orders-api -n orders follows the rollout and reports when it completes or stalls.
The following diagram shows the state of a Kubernetes rollout stalled by a failing readiness probe, and the developer's next steps.

Rolling update arithmetic
Rollbacks and history
Each change to the Pod template is recorded as a revision of the Deployment, kept as an old ReplicaSet scaled to zero. kubectl rollout history lists the revisions, and kubectl rollout undo returns to the previous one, or to a specific revision with --to-revision. A rollback is itself a rolling update in the opposite direction.
kubectl rollout status deployment/orders-api -n orders
kubectl rollout history deployment/orders-api -n orders
kubectl rollout undo deployment/orders-api -n ordersA rollback with kubectl changes the cluster but not the manifest in source control, so the files must be corrected too, or the next apply will reintroduce the faulty image. Teams that use GitOps tools, such as the Flux extension for AKS, roll back by reverting the commit instead.
Managing manifests for several environments
The same application usually runs in development, test and production with different replica counts, image tags, resource sizes and configuration. Three approaches avoid copying whole manifests for each environment.
- Kustomize, built into kubectl as
kubectl apply -k, keeps a base set of manifests and per-environment overlays that patch specific fields. - Helm packages manifests as templated charts with a values file per environment, and is the usual way to install third-party software.
- Pipeline substitution replaces tokens such as the image tag during a CI/CD run before kubectl apply.
Whatever the approach, the deployed image should be referenced by a unique tag or digest, so that the manifest in source control identifies exactly what runs.
Manifests for several environments
A stalled rollout
A pipeline applies a manifest that changes the image of a three-replica Deployment. After ten minutes, kubectl rollout status still reports "Waiting for deployment rollout to finish: 1 out of 3 new replicas have been updated". The new Pod is Running but not Ready, and users report no errors.
The rollout is stalled by the readiness probe: the new Pod runs but never passes readiness, so the Deployment keeps the old Pods serving and does not continue. Users see no errors because only ready Pods receive traffic. The developer should inspect the new Pod with kubectl describe pod and kubectl logs to see why the health endpoint fails, and run kubectl rollout undo to return cleanly to the previous revision while the image is fixed.
Deleting the readiness probe would let the broken Pods receive traffic. Scaling the Deployment to six replicas would create more unready Pods. Deleting the old ReplicaSet would remove the working version.
Why should a team also fix the manifest in source control after running kubectl rollout undo?
Show answer
The rollback changes the cluster only. The next kubectl apply of the unchanged manifest would reintroduce the faulty image.
Exam Tips
Remember for the exam
- kubectl apply is declarative and idempotent; kubectl diff previews changes.
- Rolling updates use maxSurge and maxUnavailable (25% each by default).
- A failing readiness probe stalls a rollout while old Pods keep serving.
- kubectl rollout undo returns to the previous ReplicaSet; fix the manifest in source control too.