Learning Objectives
- Explain why bare Pods never self-heal across node failures and why Deployments wrap ReplicaSets.
- Configure CPU/memory requests & limits alongside distinct readiness and liveness probes.
Prerequisites
- Docker containers, container ports, and YAML formatting
From Ephemeral Pods to Declarative Deployments
A Kubernetes Pod holds a unique cluster IP while running, yet vanishes permanently if its host node restarts. Creating a Deployment reconciles a ReplicaSet continuously to maintain desired replica count (`replicas: 3`) and performs progressive rolling upgrades without dropping traffic when paired with proper readinessProbe gates.
Learn container optimization in Docker Multi-Stage Builds or explore EKS GitOps in AWS DevOps Career Program.
Practical Programming Examples
Production-Ready Deployment + ClusterIP Service Manifest
Define a 2-replica stateless API Deployment with resource boundaries, readiness probes, and internal ClusterIP service.
apiVersion: apps/v1
kind: Deployment
metadata:
name: courses-api
spec:
replicas: 2
selector:
matchLabels: { app: courses-api }
template:
metadata:
labels: { app: courses-api }
spec:
containers:
- name: api
image: ghcr.io/mockattempt/courses-api:1.4.0
ports: [{ containerPort: 8080 }]
readinessProbe:
httpGet: { path: /healthz, port: 8080 }
initialDelaySeconds: 5
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { cpu: 500m, memory: 256Mi }
---
apiVersion: v1
kind: Service
metadata:
name: courses-api-svc
spec:
type: ClusterIP
selector: { app: courses-api }
ports: [{ port: 80, targetPort: 8080 }]
Deployment schedules 2 healthy pods behind stable internal DNS `courses-api-svc:80`.
- Label selector `app: courses-api` ties Service endpoints dynamically to matching Ready Pods.
- `readinessProbe` prevents kube-proxy from sending user requests before `/healthz` reports HTTP 200.
Common Mistakes to Avoid
- Deploying `:latest` mutable image tags instead of pinned semantic/SHA digests.
- Omitting `resources.requests` / `limits`, letting noisy containers trigger cluster node OOM eviction.
Production Best Practices
- Separate fast `/healthz` readiness checks from heavy downstream dependency checks inside `/ready`.
- Pair Deployments with HorizontalPodAutoscaler (HPA) and PodDisruptionBudget (PDB) in multi-AZ clusters.
Technical Interview Relevance
Core Kubernetes troubleshooting interview scenario (CrashLoopBackOff, ImagePullBackOff, Pod pending diagnostics).
Practice & Self-Check Questions
Why does a Service still maintain a stable IP and DNS name even when Pods restart continuously?
Kubernetes decouples network identity (Service ClusterIP + CoreDNS record) from dynamic Pod endpoints updated by EndpointSlices whenever Pods pass readiness checks.