TL;DR
You see “exit code 137” in kubectl describe. Now what? Exit codes tell you how a container died, not why. 0 and 1 come from your application, 126 and 127 from the image or the path, and anything above 128 is a signal: subtract 128 to get it, so 137 is SIGKILL (9) and 143 is SIGTERM (15).
- Exit 137 has three causes: OOMKilled, node-pressure eviction, or a shutdown that overran its grace period. Only the
Reasonfield tells them apart. - Exit 143 is usually fine: a normal shutdown. A shell-form
CMDthat swallows SIGTERM turns it into a 137. - Start every time with two commands:
kubectl describe podandkubectl logs --previous.
Seeing 137 right now? Our OOMKilled guide covers the most common cause step by step.
You run kubectl describe pod on a crashed container. Near the bottom, under Last State: Terminated, you see a line that just says Exit Code: 137. What now?
Exit codes are the fastest signal Kubernetes gives you about why a container died. They tell you whether the container exited cleanly, hit an application error, got killed by the kernel, or was gracefully shut down by Kubernetes itself. The problem is that most references bury the useful information under 2,000 words of context or stop at the three or four codes everyone has heard of.
This piece covers the seven exit codes you will actually see in production (0, 1, 126, 127, 137, 139, 143), the 128 + N formula that lets you decode any signal-based code, the three different scenarios that all show up as code 137, and the one trap in container CMD configuration behind many dirty shutdowns. Scan the table below, or jump straight to the code you are seeing.
Quick reference table
| Code | Signal | Meaning | Common causes | First thing to check |
|---|---|---|---|---|
| 0 | None | Clean exit | Process finished normally; CMD returned; no PID 1 loop | Was the container supposed to be long-running? |
| 1 | None | General application error | Unhandled exception, bad config, missing env var, dependency failed | kubectl logs <pod> --previous |
| 126 | None | Command cannot execute | Not executable, wrong architecture binary, SELinux block | File permissions and image platform |
| 127 | None | Command not found | Typo in CMD, missing utility in slim image, wrong path | The CMD or ENTRYPOINT path |
| 137 | SIGKILL (9) | Forcibly killed | OOMKilled, node pressure eviction, or grace period expired | The Reason field in kubectl describe pod |
| 139 | SIGSEGV (11) | Segmentation fault | Null pointer, memory corruption, buggy native extension | kubectl logs --previous, then core dumps |
| 143 | SIGTERM (15) | Graceful shutdown | Normal deploy, drain, rollout, or scale-down | Whether the shutdown was clean |
How exit codes work in Kubernetes
Container exit codes come from the Unix convention: a process returns an integer between 0 and 255 when it exits, and anything above 128 usually means the process was killed by a signal. The formula is 128 + N, where N is the signal number. SIGKILL is signal 9, so 128 + 9 = 137. SIGTERM is signal 15, so 128 + 15 = 143. The full list of signal numbers is in the Linux signal(7) man page.
Kubernetes surfaces the exit code in two places:
kubectl describe pod <name>underLast State: Terminatedkubectl get pod <name> -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'
The exit code is not the whole story. The Reason field sitting next to it is just as important. A container that gets OOMKilled shows Exit Code: 137 and Reason: OOMKilled. A container that failed to shut down in time also shows Exit Code: 137 but Reason: Error. Same code, different root causes.
If there is no exit code at all, the container never started. A pod stuck in CreateContainerConfigError, for example, is waiting on a missing Secret or ConfigMap, not crashing; our CreateContainerConfigError guide and this real missing-Secret investigation cover that case.
Two commands cover most exit-code debugging:
kubectl describe pod <pod-name>
kubectl logs <pod-name> --previousThe first shows the exit code and the reason. The second shows what the container was doing just before it died. Learn to run both without thinking.
Exit Code 0: Clean exit
Exit code 0 means the process ended normally. For a one-shot job (a Kubernetes Job, a migration container, a backup script) this is what you want. For a long-running service, it is almost always a bug.
The most common cause is a container whose CMD or ENTRYPOINT returns instead of blocking. A Python script that forgot the while True: loop. A Go binary where main() ends after setup. A shell script that runs the real server with & instead of exec, so the shell exits as soon as the server starts.
To debug a surprise exit code 0:
- Check the container's
CMDandENTRYPOINT. Is the process actually supposed to block? - Look at
kubectl logs <pod> --previousfor any "finished" or "complete" message that should not have been there - If the container runs a shell script, make sure the real process is invoked with
exec, not as a background job
CMD runs ./worker &, which backgrounds the worker and lets the shell exit immediately. Fix is to drop the & or wrap the command in exec.Exit Code 1: General application error
Exit code 1 is the catch-all for an application that exited because something went wrong inside it. This covers almost every unhandled exception in your code, every missing environment variable at startup, every connection failure that the application decided was fatal, and every bad config file.
The exit code itself tells you nothing about the specific error. The logs do.
kubectl logs <pod-name> --previousThe --previous flag matters because by the time you look, the container has probably restarted. Without --previous, you are reading logs from the fresh instance, not the one that died.
What to look for in the logs depends on the language:
- Python: Full traceback with
Traceback (most recent call last):and the exception type - Node.js:
UnhandledPromiseRejectionwarnings or stack traces starting with the error class name - Go:
panic:followed by a stack trace with goroutine IDs - Java:
Exception in thread "main"followed by the stack trace, usually with a Caused by chain
CrashLoopBackOff with exit code 1 right after a new deploy. Logs show KeyError: 'DATABASE_URL'. The deploy renamed an environment variable in the Helm values file but did not update the application's config loader. The fix is five lines of code; the detection is one kubectl logs --previous. Our CrashLoopBackOff guide walks through the rest of the restart loop.Exit Code 126: Command cannot execute
Exit code 126 means the file Kubernetes tried to run exists, but the system refused to execute it. The three most common causes:
- The file is not marked as executable (
chmod +xwas never run on it) - The binary was built for a different CPU architecture than the node (ARM binary on an x86 node, or vice versa)
- SELinux, AppArmor, or a seccomp profile blocked the execution
To debug:
# Which architecture is the node, and which is the image?
kubectl get node <node-name> -o jsonpath='{.status.nodeInfo.architecture}'
docker image inspect <image> --format '{{.Os}}/{{.Architecture}}'
# Is the file there, and is it executable?
docker run --rm --entrypoint sh <image> -c 'ls -l /path/to/binary'If the image says linux/arm64 and the node says amd64, that is the problem. Running the image locally with a shell entrypoint is often easier than kubectl debug here, because a container that cannot execute its command never stays up long enough to attach to.
When the wrong-architecture binary is the container's own entrypoint, the runtime can report exec format error with exit code 255 instead of 126. That is what happened in this ClickHouse Keeper investigation, where one pod failed on a single node while its two peers kept running.
latest tag. Pods scheduled on x86 nodes crash-loop with exec format error while pods scheduled on ARM nodes work fine. The flaky behavior is the giveaway.Exit Code 127: Command not found
Exit code 127 means the binary specified in CMD or ENTRYPOINT does not exist at that path. This is almost always one of two things:
- A typo in the
CMDline (/usr/local/bin/myappinstead of/usr/local/bin/my-app) - A utility that was present in the base image but is missing after a switch to a slimmer one
The second case bites teams migrating from ubuntu or debian to alpine or distroless. Alpine ships without bash and without curl. A CMD ["sh", "-c", "bash ./startup.sh"] that worked fine on Ubuntu will exit 127 on Alpine with sh: bash: not found.
One distinction matters here. Exit code 127 comes from a shell that could not find a command. If the missing binary is the container's own exec-form CMD or ENTRYPOINT, there is no shell to report it: the container never starts, and kubectl describe pod shows Reason: StartError, usually with exit code 128 and executable file not found in $PATH. Same cause, same fix, different code.
To debug:
# Run the image locally with a shell and look for the command
docker run --rm --entrypoint sh <image> -c 'command -v bash; ls -la /usr/local/bin/'If the image has no shell at all (distroless), inspect the image layers directly with docker history <image> or your registry's image browser.
python:3.11 to python:3.11-slim to cut image size. Pods immediately exit 127. The startup script was using wget to pull a config file at boot, and the slim image does not include it. Fix is either to install wget in the image or use Python's urllib instead.Exit Code 137: SIGKILL
Exit code 137 is one of the most common exit codes engineers hit in production, and it is also the most misunderstood. The code itself means the container was killed by signal 9 (SIGKILL), which cannot be caught or ignored by the process. The hard question is who sent that SIGKILL and why.
There are three different scenarios that all show exit code 137. You have to read the Reason field in kubectl describe pod to tell them apart.
Scenario 1: OOMKilled (container exceeded its memory limit)
The container used more memory than its resources.limits.memory setting allowed. The kernel's OOM killer stepped in and terminated it.
kubectl describe podshowsReason: OOMKilled- The container is restarted by the kubelet according to the restart policy
kubectl logs --previousmay or may not show anything useful depending on how fast the kill happened
Debug by checking:
kubectl describe pod <name> | grep -A 5 "Last State"
# To see kernel-level OOM events on the node (dmesg needs a privileged debug pod):
kubectl debug node/<node-name> -it --image=busybox --profile=sysadmin
# Then: dmesg | grep -i oomFix options: raise the memory limit, fix the memory leak in the application, or add horizontal pod autoscaling so load is spread across more pods. Our OOMKilled guide covers each fix, and this real OOMKilled investigation shows one unbounded query breaching a 2.5 GB limit while the node itself sat almost idle.
Scenario 2: Node pressure eviction (node ran out of memory)
The node itself ran out of memory, and the kubelet evicted pods to free resources. Different mechanism than OOMKilled, same visible exit code: under a hard eviction threshold the kubelet uses a zero-second grace period, so the container gets SIGKILL straight away.
kubectl describe podshowsReason: Evicted- The pod's events include an
Evictedevent with details likeThe node was low on resource: memory - The kubelet does not evict strictly by QoS class. It ranks pods by whether their usage exceeds their requests, then by priority, then by usage relative to requests. In practice
BestEffortpods (no requests) go first andGuaranteedpods go last (node-pressure eviction docs). In this Trino investigation, pods with no requests or limits were exactly the ones evicted first
Check your pod's QoS class with:
kubectl get pod <name> -o jsonpath='{.status.qosClass}'Fix: set requests and limits on all containers so the pod gets a better QoS class, or move the workload to a node pool with more memory headroom. Disk pressure evicts pods the same way; our ephemeral storage eviction guide covers that case, and this pod eviction investigation shows it in production.
Scenario 3: Grace period expired
Kubernetes sent SIGTERM for a graceful shutdown. The container did not shut down within terminationGracePeriodSeconds (default: 30 seconds). The kubelet then escalated to SIGKILL, which shows as exit code 137 instead of the clean exit code 143.
kubectl describe podshowsReason: Erroror sometimes nothing specific- The pod was being terminated as part of a deploy, rollout, or drain
- You will see a
Killingevent in the pod events followed by the SIGKILL
Fix: either make the application shut down faster when it receives SIGTERM, add a preStop lifecycle hook, or increase terminationGracePeriodSeconds on the pod spec.
A note on cgroup v2
Most new clusters (Kubernetes 1.25+) run cgroup v2, which handles OOM events differently from cgroup v1. On cgroup v2 nodes the kubelet sets memory.oom.group on each container, so an OOM kill takes down every process in that container together, not just the single largest process. The kubelet's singleProcessOOMKill setting restores the old behavior (Kubernetes blog on the shift to cgroup v2). If you are seeing whole containers restart where only a worker process used to die, check whether your cluster is on cgroup v2 with stat -fc %T /sys/fs/cgroup/ on any node.
CrashLoopBackOff. The Reason: OOMKilled on the first kubectl describe was the only diagnostic needed. Fix: added a size-bounded LRU to the cache.Exit Code 139: SIGSEGV / Segmentation fault
Exit code 139 means the process accessed memory it was not allowed to touch. The kernel kills the process with signal 11 (SIGSEGV). This is almost always a bug in the application code or in a native library it depends on.
Common causes:
- Null pointer dereference in C, C++, Rust (unsafe), or Go cgo code
- Buffer overflow or memory corruption
- Buggy native extension in Python (NumPy, TensorFlow, Pillow built against the wrong system libraries)
- JVM native code failure (less common with modern JVMs but still happens)
- A JIT compiler bug in the language runtime itself
Logs are often empty because the process did not get a chance to flush them before dying. The techniques that help:
# First, check if there are any previous logs at all
kubectl logs <pod> --previous
# Enable core dumps on the node (requires node-level access)
# Then inspect with gdb or language-specific toolsLanguage-specific debugging:
- Python: Enable the
faulthandlermodule at startup. It prints a Python stack trace when the process gets SIGSEGV, even from a native extension - Java: The JVM writes an
hs_err_pid<N>.logfile with register state and the failing frame. Mount a volume to catch it - C/C++: Build with AddressSanitizer (
-fsanitize=address) in a debug image to catch the bad access with context - Go:
debug.SetTraceback("crash")fromruntime/debug, or environment variableGOTRACEBACK=crashprints a stack trace on SIGSEGV
kubectl logs --previous is empty. Enabling faulthandler in the application entrypoint reveals that a NumPy call is segfaulting. Turns out the Python wheel for NumPy was built against a different glibc version than the one in the container's base image. Rebuilding NumPy against the correct glibc fixes it.Exit Code 143: SIGTERM / Graceful shutdown
Exit code 143 is the one exit code that is usually not a bug. Kubernetes sends SIGTERM to a container when it wants that container to shut down, which happens all the time during normal operations: a rolling deploy, a scale-down event, a node drain, a pod rescheduling. If the container shuts down cleanly within the grace period, you get exit code 143. Fine.
Where 143 becomes a problem is when the shutdown is not clean. The pod went away, but it did so with in-flight requests dropped, half-written data, buffers unflushed, or connections hard-closed instead of gracefully closed.
The biggest cause of dirty 143 shutdowns is a CMD or ENTRYPOINT written in shell form instead of exec form.
# Shell form: sh -c wraps your command, and sh does NOT forward signals
CMD ./myapp --config /etc/config.yaml
# Exec form: your process receives signals directly
CMD ["./myapp", "--config", "/etc/config.yaml"]With shell form, Docker (and therefore Kubernetes) actually runs /bin/sh -c "./myapp --config /etc/config.yaml". The shell becomes PID 1 in the container, and it does not forward signals to your application (Dockerfile reference). SIGTERM goes to the shell, which does nothing with it, and your application never gets told to shut down. After the grace period expires, the kubelet escalates to SIGKILL (which you now see as 137 instead of 143).
Other common causes of dirty 143 shutdowns:
- Application does not have a SIGTERM handler at all; it just gets killed when the grace period expires
- Application has a long-running operation that cannot be interrupted (large file writes, batch jobs)
terminationGracePeriodSecondsis set too low for how long the application actually needs to shut down
Fixes:
- Switch all
CMDandENTRYPOINTstatements to exec form - Add a SIGTERM handler to your application that drains in-flight requests before exiting
- Add a
preStoplifecycle hook that gives dependencies (load balancers, service meshes) time to stop sending traffic before the container shuts down - Tune
terminationGracePeriodSecondsto match how long your application actually needs
CMD is shell form: CMD python worker.py. SIGTERM is never reaching the Python process. Switching to CMD ["python", "worker.py"] and adding a SIGTERM handler that finishes the current message before exiting fixes both the dirty shutdowns and the duplicates.The 128 + N formula and other signals
Any exit code above 128 almost always came from a signal. The formula is:
exit_code = 128 + signal_numberSo if you see an exit code you don't recognize that is above 128, subtract 128 and look up the signal. The common ones:
| Exit code | Signal | Name | What it means |
|---|---|---|---|
| 130 | 2 | SIGINT | Interrupt, such as Ctrl+C in an attached kubectl run -it or docker run -it session |
| 131 | 3 | SIGQUIT | Quit, generates a core dump |
| 134 | 6 | SIGABRT | Process called abort() itself (assertion failures in C/C++) |
| 137 | 9 | SIGKILL | Forcibly killed, cannot be caught |
| 139 | 11 | SIGSEGV | Segmentation fault |
| 143 | 15 | SIGTERM | Graceful termination request |
If a C++ service panics with an assertion failure, you will usually see exit code 134 (SIGABRT). If someone presses Ctrl+C in an attached interactive container, you will see exit code 130 (SIGINT). None of these show up in most Kubernetes exit code guides, but they are real and they do happen.
Codes below 128 other than 0, 1, 126 and 127 are whatever the application chose to exit with. A Rust panic, for example, exits with 101, which is what this CrashLoopBackOff investigation turned on: exit 101, not 137, so the OOM theory was ruled out in the first step. Trino uses 100 for config validation failures, which is how this Trino BigQuery investigation separated a missing JVM argument from a bad image.
The decision tree
When you see an unfamiliar exit code, work through this:
-
Is it 0 and the container was supposed to be long-running? The
CMDorENTRYPOINTis returning when it should block. Check for a missing loop, a backgrounded process, or a shell script that is not usingexec. -
Is it 1? Application error. Run
kubectl logs <pod> --previousand read the stack trace. -
Is it 126 or 127? Image or path problem. The binary either cannot execute (126) or does not exist at the path (127). Check
CMD, image architecture, and whether the binary is present in the image. AReason: StartErrorwith exit code 128 means the exec-form entrypoint itself is missing. -
Is it 137? Check the
Reasonfield first.OOMKilled→ container exceeded its memory limitEvicted→ the node ran out of memoryErroror empty → likely a grace-period expiry
-
Is it 139? Code bug or buggy native dependency. Enable language-specific crash handlers (
faulthandlerfor Python,GOTRACEBACK=crashfor Go, hs_err logs for Java) to get a stack trace. -
Is it 143? Usually fine (normal shutdown). Only worry if the shutdown was dirty. Check for shell-form
CMD, missing SIGTERM handlers, or a grace period that is too short. -
Is it above 128 and not one of the above? Subtract 128 to find the signal number, then look it up. Common ones are SIGINT (130), SIGQUIT (131), and SIGABRT (134).
The three commands you will run every time:
# What happened?
kubectl describe pod <name>
# What was it doing before it died?
kubectl logs <name> --previous
# If you need to inspect the running container's processes or environment:
kubectl debug pod/<name> -it --image=busybox --target=<container>The last one starts an ephemeral container that shares the target container's process namespace, so it only works while the container is running.
What exit codes don't tell you
Exit codes are the fastest signal Kubernetes gives you. They point you at the right category of problem, often within seconds of kubectl describe pod. What they do not tell you is why the problem happened in the first place.
An exit code 137 OOMKill tells you the container ran out of memory. It does not tell you that the memory consumption started climbing right after the deploy that landed four hours ago, that only one specific endpoint is driving the growth, or that a cache invalidation bug is keeping memory from being released. For that you need to correlate the exit code with recent changes, with resource metrics around the kill, and with logs from before the exit. We walk through that correlation step by step in how to use AI to debug Kubernetes incidents.
That correlation work is where AI SRE tools like Sherlocks AI earn their keep: pulling the recent deploy events, the memory time series, the log patterns, and the related signals into a single investigation and surfacing the probable root cause with evidence. But even manually, the three commands at the top of this piece will get you most of the way there. The exit code is where every incident starts.
FAQ
Exit code 137 means the container was killed with SIGKILL (128 + 9). In Kubernetes that happens for three reasons: the container exceeded its memory limit (Reason: OOMKilled), the node ran out of memory and evicted the pod (Reason: Evicted), or the container did not stop within its termination grace period after SIGTERM (Reason: Error).
Exit code 1 is a general application error: the process exited because something failed inside it, such as an unhandled exception, a missing environment variable, or a bad config file. The code does not say which, so run kubectl logs <pod> --previous to read the error from the container that died.
Exit code 127 means a shell inside the container could not find a command, usually a typo in CMD or a tool missing from a slimmer base image. If the missing binary is the container's own exec-form entrypoint, you see Reason: StartError with exit code 128 instead.
Exit code 139 means the process was killed by SIGSEGV (128 + 11), a segmentation fault from touching memory it was not allowed to access. It is almost always a bug in the application or a native library. Logs are often empty, so enable a crash handler such as Python's faulthandler or GOTRACEBACK=crash in Go.
Both usually mean the container failed to start rather than crashed while running. Exit code 128 with Reason: StartError typically means the exec-form entrypoint was not found. Exit code 255 can come with exec format error, which means the entrypoint binary was built for a different CPU architecture than the node.
Exit code 137 does not always mean OOMKilled. Check the Reason field in kubectl describe pod. If it says Error, the container was likely sent SIGTERM for a graceful shutdown and did not exit in time, so the kubelet escalated to SIGKILL. If it says Evicted, the node ran out of memory rather than the container exceeding its own limit.
Not usually. SIGTERM is sent during every normal pod shutdown (deploys, scaling, drains). A clean exit code 143 means the container received the signal and shut down within the grace period. It only becomes a problem if the shutdown was dirty: in-flight requests dropped, data not flushed, connections hard-closed.
Both come from signals, but different ones. Exit 143 comes from SIGTERM, which asks the process to shut down gracefully. Exit 137 comes from SIGKILL, which forcibly terminates the process. If a container ignores or does not finish responding to SIGTERM within the grace period, Kubernetes escalates to SIGKILL, which changes the exit code from 143 to 137.
SIGSEGV kills the process so suddenly that log buffers are not flushed. Enable language-specific crash handlers (faulthandler for Python, GOTRACEBACK=crash for Go, hs_err files for Java) to catch the stack trace. For C and C++ workloads, enable core dumps and inspect them with gdb.
Only if the root cause is OOMKilled from a legitimate memory need. If the container has a memory leak, raising limits will just delay the OOMKill, not prevent it. If the 137 came from a node pressure eviction, raising the pod's memory request may help, because the kubelet evicts pods whose usage exceeds their requests first. If it came from a grace-period expiry, raising memory limits has no effect at all; you need to fix the shutdown behavior.
It means the process ended normally, which is a bug for a service that was supposed to run forever. The most common cause is a CMD or ENTRYPOINT whose main process returns instead of blocking. Common sources: a shell script that backgrounds the real server with &, a Python script missing its event loop, or a Go main() that falls through after setup.
Related reading
How to fix a Kubernetes OOMKilled container (exit code 137)
The fixes for the most common 137, step by step.
How to fix a Kubernetes CrashLoopBackOff
What to do when the exit code keeps coming back.
How to Use AI to Debug Kubernetes Incidents in 2026
Correlating the exit code with deploys, metrics and logs.
AI SRE for Kubernetes
How Sherlocks AI investigates Kubernetes incidents, read-only inside your cluster.
See an AI SRE work a real incident
Book 30 minutes with our team and watch an investigation run on your own stack.
Book a demo →