Health Endpoint Types
Kubernetes uses three probe types: liveness, readiness, and startup. Each serves a different purpose and should check different things.
| Probe | Purpose | Checks |
|---|
| Liveness | Detect deadlocks/hangs | Process responsive only |
| Readiness | Accept traffic? | All dependencies available |
| Startup | Initialization complete? | Boot sequence finished |
Gohealth-endpoint-setup.go
Separate endpoints for each probe type. /healthz for liveness. /readyz for readiness. /started for startup. Each endpoint checks only what it needs to check. Keep liveness checks simple.
Liveness Probes
Goliveness-probe-implementation.go
Liveness probes should be minimal — check that the process is responsive. Do not check dependencies in liveness. If the process is deadlocked, the probe fails and Kubernetes restarts it. Simple is better.
Readiness Probes
Goreadiness-probe-with-dependencies.go
Readiness probes check all dependencies. Use short timeouts (2 seconds) to fail fast. Report which dependency failed — it helps operators diagnose issues. Return 503 when any dependency is unavailable.
Startup Probes
Gostartup-probe-implementation.go
Startup probes run once during initialization. They give slow-starting services time to boot. The probe returns the current phase — useful for debugging slow startups. failureThreshold in Kubernetes should accommodate the slowest startup time.
Dependency Checks
Godependency-health-checking.go
DependencyChecker tracks the health of all dependencies. CheckAll runs all checks concurrently. IsReady returns true only if all dependencies are healthy. Use this for readiness decisions.
Degraded State
Godegraded-state-handling.go
Degraded state means some dependencies are unhealthy but the service can still function. Return 200 for healthy and degraded. Return 503 for unhealthy. This allows partial traffic during dependency failures.
Liveness: is the process alive? Check with /healthz. Readiness: can the process accept traffic? Check with /readyz. A process can be alive (liveness OK) but not ready (readiness failed) — for example, during cache warmup.