Building a zero-downtime deployment pipeline with health checks and graceful shutdown
Scenario
Context A Node.js service deployed on Kubernetes receives traffic during rolling updates, causing in-flight requests to fail when pods are terminated abruptly. The Problem The application does not handle SIGTERM gracefully, terminating active connections immediately when a new deployment starts. Constraints Implement a SIGTERM handler that stops accepting new connections and waits for in-flight requests to complete before exiting. Expose /healthz and /readyz endpoints for Kubernetes liveness and readiness probes. Set a maximum drain timeout of 30 seconds. Expected Deliverable A Node.js application with graceful shutdown on SIGTERM, Kubernetes-compatible health check endpoints, and a configurable drain timeout ensuring zero dropped requests during rolling deploys.