liveBook · Manning

Health check

As explained in Kubernetes for Developers

A health check is an operational test or signal indicating whether an application or process is functioning correctly.

A health check is a signal an application gives Kubernetes about whether it is functioning and ready to receive traffic. Kubernetes cannot infer these conditions for every service, so the application must expose a test that reports success or failure. section 4.0 section 4.1

Kubernetes uses two primary health-check roles:

  • Liveness probes identify stuck or nonresponsive applications and allow Kubernetes to restart their containers. section 4.1 section 4.3
  • Readiness probes identify replicas that can receive traffic. Kubernetes removes unready replicas from Service traffic, which helps prevent dropped requests during updates. section 4.1 section 4.3
  • A failed probe can represent a timeout, excessive load, a stopped connection listener, or an unavailable critical dependency. section 4.1

Choosing a probe type

Expose an HTTP endpoint such as /healthz and return HTTP 200 when healthy. For a non-HTTP service such as SMTP, test whether a TCP connection opens. For a batch job without a service endpoint, run a Bash script whose nonzero exit code indicates failure. section 4.1.6

readinessProbe:
  initialDelaySeconds: 15
  periodSeconds: 30
  tcpSocket:            #1
    port: 25            #1
  successThreshold: 1
  failureThreshold: 1
#1 TCP probe specification

A readinessProbe configuration can specify an initial delay, check interval, TCP port, and success or failure thresholds. section 4.1.6

How Kubernetes for Developers covers it

How deep it goes
Explains liveness, readiness, failure conditions, and HTTP, TCP, and Bash implementations, stopping short of exhaustive configuration guidance.
Examples
Demonstrates /healthz over HTTP, TCP connectivity on port 25, and Bash tests for background tasks.
What it assumes
Assumes a containerized application and introduces how that application reports health to Kubernetes.
What you can do after
Operate/configure Kubernetes probes that restart unhealthy containers and protect traffic during application updates.
How it connects
Connects health checks to liveness probes, readiness probes, Kubernetes Services, Deployments, and rolling updates.

Also explained in

Compare how 9 books explain health check →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.