Deployments: rolling update, rollback and canary
Objective
In this lab you will:
- Perform a rolling update and watch the Deployment manage its ReplicaSets
- Diagnose a stuck rollout and roll back to a working revision
- Pause a rollout to batch several changes into one revision
- Run a canary release with two Deployments behind one Service
Complete this lab in 45 minutes.
Prerequisites
- A Kubernetes cluster (kind is fine) or an OpenShift cluster, with
kubectl - The slides
C_K8s_02_standard_API.pdf, section Deployments
Note
On OpenShift, oc rollout is the same command as kubectl rollout for Deployments. It also manages the deprecated DeploymentConfigs (oc rollout latest dc/<name>), which are not covered here.
Exercise 1: create the Deployment
Questions
- Which objects did the Deployment create? How are they linked?
- How many pods can be unavailable, and how many extra pods can be created, during an update?
Exercise 2: rolling update, blue to green
In a second terminal, watch the ReplicaSets:
In $HOME/tmp/kuard.yaml, change the image to k8sschool/kuard-amd64:green and the annotation kubernetes.io/change-cause to Update to green kuard. Apply the file and monitor the update.
Exercise 3: a broken update
Update the image to k8sschool/kuard-amd64:1.9.10, with the change cause Update to kuard 1.9.10, and monitor the update. What happens? Is the application still available?
Exercise 4: history and rollback
- Display the rollout history, then the details of revision 2
- Roll back to the last working version
- Check the history again. What happened to revision 2?
Exercise 5: pause and resume
Pause the rollout, then change the image to k8sschool/kuard-amd64:purple and set a memory request of 64Mi, with kubectl set. Resume the rollout. How many new revisions were created?
Exercise 6: canary release
A rolling update replaces all the pods in a few minutes. A canary release sends a small part of the traffic to the new version, and keeps it there until it is validated.
- Expose the Deployment
kuardwith a Servicekuardwhich selects the labelapp=kuardonly - Create a Deployment
kuard-canarywith 1 replica, the imagek8sschool/kuard-amd64:greenand the labelsapp=kuard,track=canary - Check which share of the requests reaches the canary
- Promote the canary