Sub topic 14
Interpreting exit codes and termination reasons
This chapter assumes you can read kubectl describe pod output. It also assumes you know that a container's state is Waiting, Running, or Terminated. Here you will learn to read the terminated state of a crashed container and turn it into a likely cause.
Where the information lives
When a container stops, the kubelet (the node agent that runs containers) records a terminated state. In a CrashLoopBackOff pod, that record is under lastState, because the container is currently Waiting for its next restart. Fetch it with:
kubectl get pod web -o jsonpath='{.status.containerStatuses[0].lastState.terminated}'The output is JSON like this:
{"containerID":"containerd://3f2a...","exitCode":137,"finishedAt":"2026-12-05T07:30:12Z","reason":"OOMKilled","startedAt":"2026-12-05T07:30:09Z"}Two fields matter most:
exitCodeis the number the process returned to the runtime.reasonis a short label. Common values areCompleted,Error,OOMKilled, andContainerCannotRun.
Also compare startedAt with finishedAt. A run of a few seconds points to a startup problem. A run of several minutes suggests a leak, a probe kill, or a failure under load.
Reading the exit code
Exit codes follow Linux conventions. A code above 128 means the process was killed by a signal. The signal number is the code minus 128.
| Exit code | Meaning | Usual cause |
|---|---|---|
| 0 | Success | A job that finished. A long-running app that exits 0 will still be restarted under `restartPolicy: Always`. |
| 1 | General application error | An unhandled exception, bad config, or a failed dependency. Check the logs. |
| 126 | Command found but not executable | Missing execute permission on the entrypoint file. |
| 127 | Command not found | A wrong `command` or `args`, or a missing binary in the image. |
| 137 | SIGKILL (128 + 9) | The kernel out-of-memory killer, or a forced kill after the termination grace period. |
| 139 | SIGSEGV (128 + 11) | A segmentation fault in native code. |
| 143 | SIGTERM (128 + 15) | A normal shutdown request. This is expected during rollouts. |
Exit code 137 alone is ambiguous. Use reason to separate the cases. OOMKilled means the container exceeded its memory limit. A 137 with reason Error often means a liveness probe failed and the kubelet killed the container, or the app ignored SIGTERM and was killed when the grace period ended.
Common errors in interpretation
- Reading
kubectl logsinstead ofkubectl logs --previous. The current container may have just started and have no useful output. - Assuming 137 always means out of memory. Confirm the reason first.
- Treating 143 as a failure. It usually shows a clean stop.
Exercise
A container shows exitCode 137 and reason Error, and its liveness probe has been failing in the events. What is the most likely cause, and what is the first thing you check?
Show answer
The kubelet probably killed the container after the liveness probe failed, which sends SIGKILL once the grace period ends. Check the probe path, port, and timing. If the app is slow to start, add a startup probe. The reason is not OOMKilled, so raising memory is not the first step.