Image

Image

Image

Image


πŸš€ 1. Core Idea (1-line)

πŸ‘‰ Deployment manages ReplicaSets and provides rolling updates + rollback


🧠 2. Why Deployment Exists

We already have:

  • Pod βœ…

  • ReplicaSet βœ…

But problem:
❌ No safe updates
❌ No version control
❌ No rollback

πŸ‘‰ Deployment solves all this


βš™οΈ 3. What Deployment Actually Does

Deployment:

  • Creates ReplicaSet

  • Manages Pods via ReplicaSet

  • Handles updates (rolling updates)

  • Maintains history (revisions)

πŸ‘‰ Flow:

Deployment β†’ ReplicaSet β†’ Pods

πŸ”₯ 4. Rolling Update (VERY IMPORTANT πŸ”₯)

Scenario:

You update image:

image: app:v2

πŸ‘‰ Kubernetes will:

  • Create new pods (v2)

  • Slowly terminate old pods (v1)

  • Ensure zero downtime


πŸ’₯ 5. Strategy Types

βœ… RollingUpdate (default)

  • Gradual replacement

  • No downtime

❌ Recreate

  • Kill all old pods first

  • Then create new ones (downtime)


πŸ“¦ 6. Example YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  selector:
matchLabels:
  app: myapp
  template:
metadata:
  labels:
app: myapp
spec:
  containers:
  - name: app
image: nginx:1.21

πŸ” 7. Rollback Feature (LIFE SAVER πŸ’―)

If new version breaks:

kubectl rollout undo deployment my-deployment

πŸ‘‰ Instantly goes back to previous working version


🧠 8. Revision History

Each update = new version stored

Check history:

kubectl rollout history deployment my-deployment

⚑ 9. Real-world DevOps Example

You deploy ML API:

  • v1 β†’ working

  • v2 β†’ bug introduced

πŸ‘‰ Deployment:

  • Detects issue (via probes / monitoring)

  • You rollback instantly

πŸ‘‰ Zero downtime + safe deploy


πŸ’Ό 10. Interview Answer (Clean)

πŸ‘‰ β€œDeployment is a higher-level Kubernetes object that manages ReplicaSets and enables declarative updates, rolling deployments, and rollbacks of applications.”


⚠️ 11. Common Mistakes

❌ β€œDeployment creates Pods directly”
πŸ‘‰ Actually β†’ creates ReplicaSet β†’ then Pods

❌ β€œPods are permanent”
πŸ‘‰ Deployment keeps replacing them


⚑ 12. CKA Commands (VERY IMPORTANT)

kubectl get deployments
kubectl describe deployment <name>
 
kubectl rollout status deployment <name>
kubectl rollout history deployment <name>
kubectl rollout undo deployment <name>

🧠 13. Memory Trick

πŸ‘‰ Deployment = Manager πŸ‘¨β€πŸ’Ό
πŸ‘‰ ReplicaSet = Worker Manager
πŸ‘‰ Pod = Worker πŸ‘·


πŸ”₯ 14. Pro Insight (Real-world)

πŸ‘‰ You will use Deployment 90% of the time

  • Backend apps

  • APIs

  • ML services