Add readiness and liveness probes to a Python service: /readyz and /livez endpoint design, dependency checks with timeouts, graceful SIGTERM shutdown, and container/K8s probe wiring (httpGet, initialDelaySeconds). Triggers on: add a health endpoint, readiness vs liveness, health check failing, graceful shutdown, K8s probe config, service won't stop on deploy.
./install.sh health-checksname: "health_checks" description: "Add readiness and liveness probes to a Python service: /readyz and /livez endpoint design, dependency checks with timeouts, graceful SIGTERM shutdown, and container/K8s probe wiring (httpGet, initialDelaySeconds). Triggers on: add a health endpoint, readiness vs liveness, health check failing, graceful shutdown, K8s probe config, service won't stop on deploy." metadata: { "includeInPrompt": true }
Give a Python service a correct health surface: separate readiness (may this instance take traffic?) from liveness (is the process stuck and worth restarting?), so dependency outages never trigger restarts and deploys drain cleanly. Scoped to HTTP endpoints, shutdown handling, and container probe wiring — not metrics or alerting.
/livez answers "is the process alive?"; /readyz answers "can it serve traffic right now?". Verified locally: with the dependency down, /readyz returned 503 while /livez stayed 200 — the orchestrator stops routing but does not restart the pod.socket.create_connection((host, port), timeout=2) — a dead dependency failed fast with detail instead of hanging the probe. Return 503 naming what failed; keep total check time under the probe's own timeout.200 {"status":"ok","checks":{"dep":"tcp 127.0.0.1:9999 ok"}} 503 {"status":"not_ready","checks":{"dep":"tcp 127.0.0.1:9999 failed: Connection refused"}} Prefer 503 (not 500) for "not ready": it reads as "route elsewhere", while 500 reads as a bug in your handler./readyz immediately returns 503 and the load balancer stops sending traffic; finish in-flight requests; then exit inside the grace window. Verified: SIGTERM flipped readiness to 503 at once, an in-flight 2-second request completed 200, and the process exited 0 within the grace period.yaml
livenessProbe: { httpGet: { path: /livez, port: 8080 }, periodSeconds: 10 }
readinessProbe: { httpGet: { path: /readyz, port: 8080 }, initialDelaySeconds: 15, periodSeconds: 5, failureThreshold: 2 }
terminationGracePeriodSeconds: 30
initialDelaySeconds must exceed your slowest cold start or slow starters get kill-looped; terminationGracePeriodSeconds must exceed your drain + shutdown time.
After applying this skill, an agent should produce:
/livez and /readyz handlers (or one documented /health treated strictly as readiness) with a sample 200 and a sample 503 response, including per-check detail.initialDelaySeconds justified against measured startup time and grace periods consistent with the shutdown handler.periodSeconds should be comfortably larger than the cost of one full check round, or probes become load.publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e
No ratings yet — be the first to rate it.