Container health checks and graceful shutdown patterns

12601
0

Health checks verify container readiness and liveness. The HEALTHCHECK Dockerfile instruction defines container-level checks. Kubernetes readinessProbe gates traffic routing—failing probes remove Pods from Service endpoints. livenessProbe detects deadlocked processes and triggers restarts. startupProbe handles slow-starting applications. HTTP probes check endpoints, TCP probes verify port connectivity, and exec probes run commands. Graceful shutdown handles SIGTERM to drain connections before stopping. The preStop lifecycle hook delays shutdown for load balancer updates. terminationGracePeriodSeconds sets the maximum shutdown time. Connection draining ensures in-flight requests complete. Proper health checks and shutdown prevent dropped requests during deployments.