Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Workloads Kubernetes Kubernetes: From Zero to Production Module 3 - Pods and Workloads

Deployments - Managing Pod Replicas and Updates

Reviewed & accurate
AI Summary

What You Will Learn

Beginner

  • How Deployments work
  • Scaling and updating
  • Rolling updates and rollbacks
Deployment -> ReplicaSet -> PodsDeploymentManages rollout, updates, rollbackReplicaSetMaintains N replicasPod 1Container(s)Pod 2Container(s)Pod 3Container(s)Pod 4 (new)Scaling up
Deployment creates ReplicaSet which maintains desired Pod count
deployment.yamlyaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3              # Desired number of Pods
  selector:
    matchLabels:
      app: my-app
  template:                # Pod template
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: app
        image: nginx:1.25
        ports:
        - containerPort: 80
Terminalbash
# Create
kubectl apply -f deployment.yaml

# Check
kubectl get deployments
kubectl get pods

# Scale to 5 replicas
kubectl scale deployment my-app --replicas=5

# Update image (rolling update)
kubectl set image deployment/my-app app=nginx:1.26

# Check rollout status
kubectl rollout status deployment/my-app

# Rollback if something went wrong
kubectl rollout undo deployment/my-app

# View rollout history
kubectl rollout history deployment/my-app
Rolling updates
When you update the image, K8s creates a new Pod, waits for it to be healthy, then kills an old Pod. Zero downtime! If the new version fails, rollback with one command.

Practical Exercise

Create deployment.yaml with 3 replicas
Apply: kubectl apply -f deployment.yaml
Scale: kubectl scale deployment my-app --replicas=5
Update: kubectl set image deployment/my-app app=nginx:1.26
Rollback: kubectl rollout undo deployment/my-app

Key Takeaways

  • Deployment manages a set of Pods (replicas).
  • Scale: kubectl scale deployment X --replicas=N.
  • Update: kubectl set image (triggers rolling update).
  • Rollback: kubectl rollout undo (instant revert).
  • Rolling update = zero downtime. Old Pods replaced one by one.
Previously: Lesson 13 covered multi-container Pods.
Today: You learned: The most common workload - managing replicas and updates.
Next: Lesson 15 covers ReplicaSets.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments