Challenge - Deployment
- Docker & Kubernetes course
- Intermediate
- Lesson 79/82
- 5 min
Write a Deployment with three replicas.
Challenge: a safely updating Deployment
In this challenge you'll define a Deployment that updates without downtime, then upgrade a version and roll it back. The two conditions for zero downtime: maxUnavailable: 0 and a readinessProbe that really measures whether new pods are ready.
kubectl apply -f api.yaml
kubectl set image deploy/api api=api:1.1
kubectl rollout status deploy/api
# a problem appeared:
kubectl rollout undo deploy/apiPractice The deployment definition
Write a Deployment YAML: name api, replicas: 3; a RollingUpdate strategy with maxSurge: 1, maxUnavailable: 0; selector and template label app: api; container named api, image api:1.0.
Starter code
# buraya yazSample solution
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: api:1.0Expected output
deployment.apps/api created
Practice Upgrade and roll back
Write four commands: set the image of the api container in the api deployment to api:1.1; wait for the rollout to finish; show the history; roll back to the previous version.
Starter code
# buraya yazSample solution
kubectl set image deployment/api api=api:1.1
kubectl rollout status deployment/api
kubectl rollout history deployment/api
kubectl rollout undo deployment/apiExpected output
deployment.apps/api image updated deployment "api" successfully rolled out REVISION CHANGE-CAUSE 1 <none> 2 <none> deployment.apps/api rolled back
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Why isn't maxUnavailable: 0 enough without a readinessProbe?
- The update never starts
- maxUnavailable is ignored
- Pods aren't deleted
- The container counts as ready as soon as it starts; the old ones close before the app is ready Correct answer
Explanation: Without a readiness signal, Kubernetes can't know when the app is ready.
2 Go back to the previous version.
kubectl rollout ____ deploy/api
kubectl rollout undo deploy/api
Explanation: rollout undo returns to the previous ReplicaSet.
3 Match.
| Term | Meaning |
|---|---|
maxUnavailable: 0 |
Capacity doesn't drop |
maxSurge: 1 |
One extra pod |
set image |
Upgrade the version |
rollout undo |
Roll back |