CodeBlanks Logo Icon CodeBlanks

Summary - Deployment

Combine YAML, replicas and rollout to manage a Deployment.

Summary: Deployment

In this group:

  • The Deployment → ReplicaSet → Pod chain; a new ReplicaSet opens when the template changes.
  • YAML: apps/v1, replicas, selector.matchLabels (must match the template label), template; resources requests/limits.
  • Scaling: declarative (replicas + apply) or kubectl scale; rollout status waits.
  • Rolling update: maxSurge/maxUnavailable; set image and the change-cause annotation.
  • rollout history/undo/pause/resume/restart handle version management.
kubectl apply -f web.yaml
kubectl rollout status deploy/web
kubectl rollout undo deploy/web

Practice A deployment with a safe strategy

Write a Deployment YAML: name web, replicas: 4; under strategy, type: RollingUpdate, maxSurge: 1, maxUnavailable: 0; selector and template label app: web; container named nginx, image nginx:1.27.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: nginx
          image: nginx:1.27

Expected output

deployment.apps/web created

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 With replicas: 4, maxSurge: 1, maxUnavailable: 0, at most how many pods can run at once during an update?

  • 8
  • 3
  • 5 Correct answer
  • 4

Explanation: 4 + maxSurge 1 = 5; it never drops below 4.

2 Specify the update strategy.

Question
spec:
  strategy:
    type: ____
Answer
spec:
  strategy:
    type: RollingUpdate

Explanation: The other built-in strategy is Recreate (closes all first).

3 Match.

Term Meaning
RollingUpdate Gradual
Recreate Close all first
revisionHistoryLimit Kept ReplicaSet count
OOMKilled Memory limit exceeded

All lessons in Intermediate