https://drive.google.com/file/d/1oUzRfeaB33aht95JwtJKTa7A0d7VrXtB/view?usp=sharing
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
| 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.
selector.matchLabelstemplate.metadata.labelsmaxSurge: 1 β During update, allow 1 extra Pod (total = 3)maxUnavailable: 0 β Zero downtime (always keep 2 Pods running)π― Result:
- Update starts β 3 Pods (2 old + 1 new)
- After new Pod is ready β kill 1 old β 3 Pods (1 old + 2 new)
- Repeat until all updated
exec to check if index.html exists