https://drive.google.com/file/d/1oUzRfeaB33aht95JwtJKTa7A0d7VrXtB/view?usp=sharing

πŸ” YAML Breakdown

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nnwebserver
spec:
  selector:
    matchLabels:
      run: nnwebserver          # ← Must match Pod template labels
  replicas: 2                   # ← Run 2 identical Pods
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1             # ← Allow 1 extra Pod during update
      maxUnavailable: 0       # ← Keep all Pods available during update
  template:
    metadata:
      labels:
        run: nnwebserver       # ← Labels for Pods (must match selector!)
    spec:
      containers:
        - name: nnwebserver
          image: lovelearnlinux/webserver:v2
          livenessProbe:       # ← Health check
            exec:
              command: ["cat", "/var/www/html/index.html"]
            initialDelaySeconds: 10
            periodSeconds: 20
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "200m"
              memory: "256Mi"
          ports:
            - containerPort: 80


πŸ“Œ Why Use a Deployment (vs Bare Pod)?

Feature Bare Pod Deployment
Replication ❌ 1 Pod only βœ… replicas: N
Self-healing ❌ Dies forever βœ… Restarts failed Pods
Rolling Updates ❌ Manual βœ… Zero-downtime updates
Rollback ❌ Impossible βœ… kubectl rollout undo
Scaling ❌ Manual βœ… kubectl scale

βœ… Deployments manage ReplicaSets, which manage Pods β†’ 3-layer controller pattern.


πŸ”‘ Key Concepts Explained

1. selector.matchLabels

2. RollingUpdate Strategy

🎯 Result:

3. Liveness Probe