Kubernetes · Reference

Kubernetes Exit Codes Explained: 0, 1, 126, 127, 137, 139, 143 and What Each Means

By Ayush M.Published on: Oct 22, 202620 min read

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 Reason field tells them apart.
  • Exit 143 is usually fine: a normal shutdown. A shell-form CMD that swallows SIGTERM turns it into a 137.
  • Start every time with two commands: kubectl describe pod and kubectl 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

CodeSignalMeaningCommon causesFirst thing to check
0NoneClean exitProcess finished normally; CMD returned; no PID 1 loopWas the container supposed to be long-running?
1NoneGeneral application errorUnhandled exception, bad config, missing env var, dependency failedkubectl logs <pod> --previous
126NoneCommand cannot executeNot executable, wrong architecture binary, SELinux blockFile permissions and image platform
127NoneCommand not foundTypo in CMD, missing utility in slim image, wrong pathThe CMD or ENTRYPOINT path
137SIGKILL (9)Forcibly killedOOMKilled, node pressure eviction, or grace period expiredThe Reason field in kubectl describe pod
139SIGSEGV (11)Segmentation faultNull pointer, memory corruption, buggy native extensionkubectl logs --previous, then core dumps
143SIGTERM (15)Graceful shutdownNormal deploy, drain, rollout, or scale-downWhether 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:

  1. kubectl describe pod <name> under Last State: Terminated
  2. kubectl 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:

bash
kubectl describe pod <pod-name>
kubectl logs <pod-name> --previous

The 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 CMD and ENTRYPOINT. Is the process actually supposed to block?
  • Look at kubectl logs <pod> --previous for 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
Scenario: A worker container is supposed to consume messages from a queue forever. It restarts cleanly every few seconds with exit code 0. Turns out the Dockerfile's 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.

bash
kubectl logs <pod-name> --previous

The --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: UnhandledPromiseRejection warnings 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
Scenario: A pod enters 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:

  1. The file is not marked as executable (chmod +x was never run on it)
  2. The binary was built for a different CPU architecture than the node (ARM binary on an x86 node, or vice versa)
  3. SELinux, AppArmor, or a seccomp profile blocked the execution

To debug:

bash
# 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.

Scenario: A team pushed a multi-arch image but accidentally tagged the ARM build with the 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:

  1. A typo in the CMD line (/usr/local/bin/myapp instead of /usr/local/bin/my-app)
  2. 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:

bash
# 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.

Scenario: A team swapped their base image from 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 pod shows Reason: OOMKilled
  • The container is restarted by the kubelet according to the restart policy
  • kubectl logs --previous may or may not show anything useful depending on how fast the kill happened

Debug by checking:

bash
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 oom

Fix 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 pod shows Reason: Evicted
  • The pod's events include an Evicted event with details like The 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 BestEffort pods (no requests) go first and Guaranteed pods 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:

bash
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 pod shows Reason: Error or sometimes nothing specific
  • The pod was being terminated as part of a deploy, rollout, or drain
  • You will see a Killing event 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.

Scenario: A team deployed a new version of their checkout service that added an in-memory cache. Memory usage climbed from 400 MB to 1.2 GB within a few minutes of each pod start. The limit was 1 GB. Every pod OOMKilled, restarted, and OOMKilled again, cycling forever in 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:

bash
# 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 tools

Language-specific debugging:

  • Python: Enable the faulthandler module 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>.log file 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") from runtime/debug, or environment variable GOTRACEBACK=crash prints a stack trace on SIGSEGV
Scenario: A Python ML service running in Kubernetes crashes with exit code 139 under load. 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.

dockerfile
# 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)
  • terminationGracePeriodSeconds is set too low for how long the application actually needs to shut down

Fixes:

  • Switch all CMD and ENTRYPOINT statements to exec form
  • Add a SIGTERM handler to your application that drains in-flight requests before exiting
  • Add a preStop lifecycle hook that gives dependencies (load balancers, service meshes) time to stop sending traffic before the container shuts down
  • Tune terminationGracePeriodSeconds to match how long your application actually needs
Scenario: A worker that processes messages from a queue is getting killed during every deploy. The team is seeing duplicate message processing after each rollout. The 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_number

So 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 codeSignalNameWhat it means
1302SIGINTInterrupt, such as Ctrl+C in an attached kubectl run -it or docker run -it session
1313SIGQUITQuit, generates a core dump
1346SIGABRTProcess called abort() itself (assertion failures in C/C++)
1379SIGKILLForcibly killed, cannot be caught
13911SIGSEGVSegmentation fault
14315SIGTERMGraceful 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:

  1. Is it 0 and the container was supposed to be long-running? The CMD or ENTRYPOINT is returning when it should block. Check for a missing loop, a backgrounded process, or a shell script that is not using exec.

  2. Is it 1? Application error. Run kubectl logs <pod> --previous and read the stack trace.

  3. 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. A Reason: StartError with exit code 128 means the exec-form entrypoint itself is missing.

  4. Is it 137? Check the Reason field first.

    • OOMKilled → container exceeded its memory limit
    • Evicted → the node ran out of memory
    • Error or empty → likely a grace-period expiry
  5. Is it 139? Code bug or buggy native dependency. Enable language-specific crash handlers (faulthandler for Python, GOTRACEBACK=crash for Go, hs_err logs for Java) to get a stack trace.

  6. 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.

  7. 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:

bash
# 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

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 →