CodeBlanks Logo Icon CodeBlanks

Challenge - Deployment

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/api

Practice 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

terminal
# buraya yaz

Sample solution

terminal
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.0

Expected 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

terminal
# buraya yaz

Sample solution

terminal
kubectl set image deployment/api api=api:1.1
kubectl rollout status deployment/api
kubectl rollout history deployment/api
kubectl rollout undo deployment/api

Expected 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.

Question
kubectl rollout ____ deploy/api
Answer
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

All lessons in Intermediate