liveBook · Manning

Exec probe

As explained in Kubernetes in Action, Second Edition

An exec probe is a Kubernetes liveness-check mechanism that runs a command inside a container and succeeds when the command exits with code zero before its timeout.

An exec probe checks container health by running a command inside the container. Exit code zero means success; a non-zero exit code or timeout means failure. It suits applications that do not expose an HTTP health endpoint or accept TCP connections. section 6.2.2 section 6.2.5

A command-based liveness check

Configure the probe to run /usr/bin/healthcheck every two seconds. With timeoutSeconds set to 1 and failureThreshold set to 1, one command failure or timeout marks the container unhealthy and causes termination as configured. section 6.2.5

    livenessProbe:
      exec:
        command:                   #1
        - /usr/bin/healthcheck     #1
      periodSeconds: 2      #2
      timeoutSeconds: 1        #3
      failureThreshold: 1    #4

Use the manifest listing to see the exec command, polling interval, timeout, and failure threshold together. section 6.2.5

Design the command and its failure behavior carefully:

  • Keep the command available on the container’s filesystem, because Kubernetes executes it inside the container. section 6.2.5
  • Keep probe handlers lightweight; their CPU and memory use counts against the container and can reduce resources available to the application. section 6.2.7
  • Avoid retry loops inside the command; use failureThreshold when several failed attempts should be required. section 6.2.7
  • Do not confuse liveness with readiness: a failed readiness probe removes the pod from service endpoints rather than restarting it. section 11.6.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines exit-code and timeout semantics, shows a manifest, and notes resource costs without detailing implementation internals.
Examples
Runs /usr/bin/healthcheck every two seconds with a one-second timeout and failureThreshold of one.
What it assumes
Assumes a command available on the container filesystem and distinguishes applications lacking HTTP endpoints or TCP connections.
What you can do after
Configure an exec liveness probe and select lightweight command, timeout, and failure-threshold settings.
How it connects
Connects liveness probes with HTTP GET, TCP socket, readiness probes, startup probes, and container lifecycle.

Also explained in

Compare how 2 books explain exec probe →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.