Container Errors — OOMKilled, Exit Codes, Probes and Stale Images
Failures inside the container boundary: OOM kills, exit codes 1, 126, 127, 139, 143 and 255, StartError, readiness and liveness probe failures, and stale images, each with the mechanism, the commands and the EKS, AKS and GKE view.
Overview
At this layer the pod was scheduled and the image was pulled, so the problem is the process itself or the box it runs in. The runtime could not start the entrypoint, the process started and then exited, the kernel killed it, or it runs but Kubernetes will not send it traffic. One more failure hides here too: everything looks healthy, yet the old build is still the one serving.
Work outside-in, the same way every time. First read Reason and Exit Code in Last State, then read the previous container's log, and only then change something. The exit code already tells you which part of the system acted. Codes above 128 mean a signal killed the process, and the signal number is the code minus 128: 137 is SIGKILL (9), 143 is SIGTERM (15), 139 is SIGSEGV (11). Codes up to 128 came from the process, or from a shell inside the container.
The one idea to keep: find out who stopped the process. The kernel (OOMKilled), the kubelet (a failed liveness probe, or the end of the grace period), the runtime (StartError) and the application (exit 1) each leave a different trace. Each one needs a different fix, and raising a limit fixes only one of them.
Symptom to first command
This page covers nine symptoms. For each one, here is the most likely cause and the first command to run.
- Reason: OOMKilled, exit 137, restarts on a cycle: the memory limit is below the real working set, or a runtime heap is sized too close to it. Start with kubectl get pod -n prod -o jsonpath='{.status.containerStatuses[*].lastState}'.
- Reason: Error, exit 1 or 255, CrashLoopBackOff: the application gave up because a dependency, config or migration failed; 255 can also be an entrypoint the runtime could not exec. Start with kubectl logs -n prod --previous.
- Exit 126, or StartError with permission denied: the entrypoint is not executable, the user is wrong, or the mount is noexec. Start with kubectl describe pod -n prod and read the Message line.
- Exit 127, or StartError with no such file or directory: a wrong path, a binary not copied into the final stage, no shell in the image, or a missing dynamic loader. Start with docker run --rm --entrypoint sh -c 'ls -l /usr/local/bin/'.
- 0/1 Running, zero restarts, 503 at the Ingress: the readiness probe is failing, so the pod is left out of the EndpointSlice. Start with kubectl get endpointslices -n prod -l kubernetes.io/service-name=orders.
- Rollout is done but the old behavior remains: an unchanged or mutable tag, a cached image, or a GitOps revert. Start with kubectl get pods -n prod -l app=orders -o jsonpath='{..imageID}'.
- Exit 143 or 137 with Reason: Error during deploys: a slow shutdown, where the grace period ran out or SIGTERM never reached the app. Start with kubectl get deploy orders -n prod -o jsonpath='{.spec.template.spec.terminationGracePeriodSeconds}'.
- Exit 139: a segmentation fault in native code, or a libc mismatch. Start with kubectl logs -n prod --previous --tail=50.
- Restarts under load, with failed liveness probe events: CPU throttling makes a strict liveness probe time out, or liveness checks a dependency. Start with kubectl events -n prod --for pod/.
The figure follows a container from its image to live traffic, and marks where each of those failures happens.
Key concepts
- Exit codes above 128
- StartError (exit 128)
- cgroup v2 memory.max
- Working set
- CFS quota throttling
- Readiness, liveness and startup probes
- Termination grace period
- Native sidecar
- Image digest
- In-place pod resize
Interview questions
- A Java service in prod restarts every few hours with exit code 137. The team already doubled the memory limit once. Walk me through it.
- After a deploy, the orders pods show 0/1 Running with zero restarts, and users get 503 from the Ingress. What happened, and how do you prove it?
- A pipeline says the deploy succeeded, but the new feature is not live. How do you find out what is running, and how do you make this impossible?
- A container fails with 'exec: /app/entrypoint.sh: permission denied'. One engineer says the code is 126, another says it is 128. Who is right?
- Every rolling update produces a burst of 502s and a few pods end with exit 137. There is no memory pressure. Explain.
- Pods restart under peak load, all at once, with 'failed liveness probe' events, but CPU averages 40 percent of the limit. What is going on?
- How does diagnosing an OOM kill or a bad probe differ on EKS, AKS and GKE?
Sign up free to read the full topic
More DevOps topics
- CircleCI
- Cloud-Native IaC
- Cluster API and Declarative Cluster Lifecycle
- CMake for Cross-Platform C++
- CNCF Landscape & Cloud Native Ecosystem
- Configuration Drift
- Container Fundamentals
- Container Image Hardening
- Container Probes — Liveness, Readiness, Startup
- Container Runtime Security
- containerd and Container Runtimes
- Continuous Delivery vs Deployment
Start free on Cariara · Coding problems · System design studio