Stage 3 · Build
Observability & Networking
Production Hardening
Health checks, readiness, structured logging, and config validation for reliable services.
Health Check Endpoints
Health checks tell Kubernetes whether your process is alive and functioning. Liveness probes detect deadlocks and infinite loops. They should never depend on external resources.
Readiness Probes
Readiness probes indicate whether your service can accept traffic. They check dependencies: database connections, cache availability, and configuration loading.
Startup Probes
Startup probes run once when the container starts. They give slow-starting services time to initialize without triggering liveness failures.
Configuration Validation
Validate configuration at startup, not at runtime. Fail fast with clear error messages. Never start a service with invalid configuration.
Resource Limits
Set CPU and memory limits for your containers. This prevents one service from starving others and enables efficient bin-packing on nodes.
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: server
resources:
requests:
cpu: "100m" # 0.1 CPU cores
memory: "128Mi" # Guaranteed memory
limits:
cpu: "500m" # Max 0.5 CPU cores
memory: "512Mi" # OOMKilled if exceeded
# Liveness probe
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 15
# Readiness probe
readinessProbe:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
# Startup probe
startupProbe:
httpGet:
path: /started
port: 8080
failureThreshold: 30
periodSeconds: 2requests guarantee minimum resources. limits cap maximum usage. Set memory limits based on pprof heap profiles. Set CPU limits based on benchmark results. Monitor actual usage and adjust limits over time.
Circuit Breakers
Circuit breakers prevent cascading failures. When a dependency fails repeatedly, the breaker opens and fails fast instead of timing out on every request.
When a dependency is failing, fail fast instead of waiting for timeouts. This prevents request queuing, connection exhaustion, and cascading failures. The circuit breaker pattern is essential for microservice resilience.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.