liveBook · Manning

Exit code

As explained in Kubernetes in Action, Second Edition

An exit code is a numeric result returned by a process when it terminates, conventionally indicating success or failure.

An exit code is the numeric result a process returns when it terminates. In container health checks, exit code 0 means the command succeeded; a non-zero code indicates failure. section 6.2.5

Exit codes also help distinguish how a container stopped. Code 0 indicates graceful self-termination, while code 137 means the process was killed. More generally, code 128+n indicates termination by external signal n; code 143 represents SIGTERM. section 6.2.4

Inspecting a restarted container

After a failed liveness probe causes a restart, kubectl describe pod can show the previous container's exit code. kubectl logs -p can then reveal whether the process caught SIGTERM and shut down gracefully. section 6.2.4

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

An exec liveness probe runs /usr/bin/healthcheck inside the container and treats exit code 0 as healthy; non-zero results trigger the configured failure behavior. section 6.2.5

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains zero, non-zero, 128+n, 137, and 143 codes, then applies them to probes, restarts, signals, and logs.
Examples
Demonstrates exit code 0 after graceful termination, code 137 after killing, and command results from an exec liveness probe.
What it assumes
Assumes familiarity with containers and liveness probes while defining exit-code meanings through concrete Kubernetes behavior.
What you can do after
Diagnose/debug with it by inspecting pod status, interpreting termination codes, and retrieving logs from the previous container.
How it connects
Connects exit codes with liveness probes, containers, process signals, graceful shutdown, and Kubernetes restarts.

Also explained in

Compare how 2 books explain exit code →

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.