🚀 Kubernetes Deployments & ReplicaSets

Master application deployment, scaling, and rolling updates in production

⏱️ 50 min read 🎯 Intermediate 🔧 20+ Examples ⚡ Production Ready

📋 Understanding Deployments

🎯 Why Deployments Matter

The Problem: Managing individual pods is complex and error-prone at scale.

The Solution: Deployments provide declarative updates for Pods and ReplicaSets.

Key Benefits: Automated rollouts, rollbacks, scaling, and self-healing.

🏭

Real-World Analogy

Think of a Deployment as a factory production line manager:

  • 🏭 Deployment = Production manager with the blueprint
  • 👷 ReplicaSet = Shift supervisor ensuring worker count
  • 🔧 Pods = Individual workers on the line
  • 📋 Desired State = Production targets to meet
  • 🔄 Rolling Update = Gradual shift changes without stopping production

Deployment Architecture

Deployment
nginx-deployment
ReplicaSet
nginx-deployment-7d9f
Pod
nginx-7d9f-x1
Pod
nginx-7d9f-x2
Pod
nginx-7d9f-x3

Basic Deployment YAML

basic-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3  # Number of pod replicas
  selector:
    matchLabels:
      app: nginx
  template:  # Pod template
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        ports:
        - containerPort: 80