CKAD — Managing Deployments
Editing Deployments
Several ways to modify a Deployment:
# Edit interactively (opens in $EDITOR)
kubectl edit deployment web
# Patch a specific field
kubectl patch deployment web -p '{"spec":{"replicas":5}}'
# Set image
kubectl set image deployment/web nginx=nginx:1.27
# Set resources
kubectl set resources deployment/web -c nginx --requests=cpu=200m,memory=256Mi
# Apply updated YAML
kubectl apply -f web-deployment.yaml
Which Method to Use
| Method | Best For |
|---|---|
kubectl edit |
Quick interactive changes |
kubectl patch |
Changing a single field programmatically |
kubectl set image |
Updating container images (most common) |
kubectl set resources |
Changing CPU/memory requests and limits |
kubectl apply -f |
Applying a complete updated YAML file |
Deployment Annotations and Labels
Add metadata to track changes:
# Annotate a Deployment
kubectl annotate deployment web kubernetes.io/change-cause="Updated nginx to 1.27"
# This shows up in rollout history
kubectl rollout history deployment/web
# REVISION CHANGE-CAUSE
# 1 <none>
# 2 Updated nginx to 1.27
# Add labels
kubectl label deployment web team=backend env=production
Exam tip: The --record flag (deprecated but still works) automatically records the command as the change cause. You can also use kubectl annotate to set kubernetes.io/change-cause manually.
Monitoring Deployments
Quick Status
# Quick status
kubectl get deployment web
# Detailed with conditions
kubectl describe deployment web
# Watch Pods being updated in real time
kubectl get pods -l app=web -w
Checking ReplicaSets
Each Deployment update creates a new ReplicaSet. The old ones are kept (scaled to 0) for rollbacks:
# Check ReplicaSets (old and new)
kubectl get rs -l app=web
# Expected:
# NAME DESIRED CURRENT READY AGE
# web-5d9f8b6c4 3 3 3 5m ← current
# web-7b4f9d3a2 0 0 0 30m ← previous
Events
# Check events for issues
kubectl get events --sort-by=.lastTimestamp | grep web
# Or use describe for resource-specific events
kubectl describe deployment web | tail -20
Deployment Conditions
kubectl get deployment web -o jsonpath='{.status.conditions[*].type}'
# Common conditions:
# Available — Minimum replicas are ready
# Progressing — Rollout is in progress
# ReplicaFailure — Cannot create Pods (e.g., resource limits)
Monitoring Quick Reference
| Task | Command |
|---|---|
| Deployment status | kubectl get deployment <name> |
| Detailed info | kubectl describe deployment <name> |
| Watch Pods | kubectl get pods -l app=<name> -w |
| ReplicaSets | kubectl get rs -l app=<name> |
| Current image | kubectl describe deployment <name> \| grep Image |
| Events | kubectl get events --sort-by=.lastTimestamp |
| JSON output | kubectl get deployment <name> -o json |
Next: Learn about advanced deployment patterns with Blue-Green & Canary →