Day 2 of 5
⏱ ~60 minutes
Kubernetes in 5 Days — Day 2

Deployments and ReplicaSets

Create Deployments for zero-downtime rollouts, scale replicas, roll back versions, and use ConfigMaps for configuration.

Deployments

A Deployment manages a ReplicaSet, which manages Pods. You tell the Deployment what you want (image, replicas) and Kubernetes makes it happen.

deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web
        image: nginx:1.24
        ports:
        - containerPort: 80
        resources:
          requests:
            memory: '64Mi'
            cpu: '100m'
          limits:
            memory: '128Mi'
            cpu: '200m'
Managing Deployments
kubectl apply -f deployment.yaml
kubectl get deployments
kubectl get pods  # should show 3 pods

# Scale
kubectl scale deployment web-app --replicas=5

# Update image (triggers rolling update)
kubectl set image deployment/web-app web=nginx:1.25

# Watch the rollout
kubectl rollout status deployment/web-app

# Roll back
kubectl rollout undo deployment/web-app
kubectl rollout history deployment/web-app
ConfigMap
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  APP_ENV: production
  LOG_LEVEL: info

# Use in a Deployment
env:
- name: APP_ENV
  valueFrom:
    configMapKeyRef:
      name: app-config
      key: APP_ENV
📝 Day 2 Exercise
Roll Out and Roll Back
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. D
  9. e
  10. p
  11. l
  12. o
  13. y
  14. m
  15. e
  16. n
  17. t
  18. w
  19. i
  20. t
  21. h
  22. 3
  23. r
  24. e
  25. p
  26. l
  27. i
  28. c
  29. a
  30. s
  31. .
  32. U
  33. p
  34. d
  35. a
  36. t
  37. e
  38. t
  39. h
  40. e
  41. i
  42. m
  43. a
  44. g
  45. e
  46. t
  47. o
  48. a
  49. n
  50. e
  51. w
  52. v
  53. e
  54. r
  55. s
  56. i
  57. o
  58. n
  59. a
  60. n
  61. d
  62. w
  63. a
  64. t
  65. c
  66. h
  67. t
  68. h
  69. e
  70. r
  71. o
  72. l
  73. l
  74. i
  75. n
  76. g
  77. u
  78. p
  79. d
  80. a
  81. t
  82. e
  83. .
  84. S
  85. i
  86. m
  87. u
  88. l
  89. a
  90. t
  91. e
  92. a
  93. b
  94. a
  95. d
  96. d
  97. e
  98. p
  99. l
  100. o
  101. y
  102. b
  103. y
  104. u
  105. s
  106. i
  107. n
  108. g
  109. a
  110. n
  111. o
  112. n
  113. e
  114. x
  115. i
  116. s
  117. t
  118. e
  119. n
  120. t
  121. i
  122. m
  123. a
  124. g
  125. e
  126. t
  127. a
  128. g
  129. .
  130. R
  131. o
  132. l
  133. l
  134. b
  135. a
  136. c
  137. k
  138. .

Day 2 Summary

  • Deployments manage the desired state. Change the spec, Kubernetes figures out how to get there.
  • Rolling updates: Kubernetes replaces Pods one at a time. No downtime during updates.
  • kubectl rollout undo reverts to the previous version instantly.
  • ConfigMaps inject configuration as environment variables without rebuilding the image.
Finished this lesson?