Room 12
DEPLOYMENTS
The Time Machine
- Deployments give you the power to travel through versions. Roll forward, roll back - control your releases.
- A deployment has been updated with a broken image. Roll it back to reveal the password.
📜 Mission Briefing
- Apply
deployment-v1.yaml- creates a deployment withnginx:1.24(3 replicas). - Check the rollout status:
kubectl rollout status deployment/time-machine. - Update the image to a broken version:
kubectl set image deployment/time-machine app=nginx:broken. - Watch the rollout fail - pods will be in ImagePullBackOff.
- Roll back:
kubectl rollout undo deployment/time-machine. - Once healthy, exec into any pod and read
/usr/share/nginx/html/password.txt.
Key Commands
| Command | Purpose |
|---|---|
kubectl create deployment NAME --image=IMG |
Create deployment |
kubectl set image deployment/NAME CONTAINER=IMAGE |
Update image |
kubectl rollout status deployment/NAME |
Check rollout progress |
kubectl rollout history deployment/NAME |
View revisions |
kubectl rollout undo deployment/NAME |
Rollback to previous |
kubectl rollout undo deployment/NAME --to-revision=N |
Rollback to specific |
kubectl scale deployment NAME --replicas=N |
Scale replicas |
How Deployments Work
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
strategy:
type: RollingUpdate # or Recreate
rollingUpdate:
maxSurge: 1 # Extra pods during update
maxUnavailable: 0 # Pods unavailable during update
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: nginx:1.24
ports:
- containerPort: 80
# Deployment lifecycle
kubectl create deployment my-app --image=nginx:1.24 --replicas=3
# Update strategies:
# RollingUpdate: Gradually replace old pods (zero-downtime)
# Recreate: Kill all old pods, then create new ones
# Perform a rolling update
kubectl set image deployment/my-app app=nginx:1.25
# Watch the rollout
kubectl rollout status deployment/my-app
# View rollout history
kubectl rollout history deployment/my-app
kubectl rollout history deployment/my-app --revision=2
# Rollback
kubectl rollout undo deployment/my-app
kubectl rollout undo deployment/my-app --to-revision=1
# Pause/resume rollouts
kubectl rollout pause deployment/my-app
kubectl rollout resume deployment/my-app
# Record changes (add --record flag, deprecated but still works)
kubectl set image deployment/my-app app=nginx:1.25
Hints
Hint 1
After the broken update, check status:
Hint 3
Read the password:
The password isrollout42.