Understanding Kubernetes Container Exit Code 137
When working with Kubernetes, it's not uncommon to encounter container exit codes. One such code, exit code 137, often raises questions among developers. This article delves into the meaning of Kubernetes container exit code 137, its causes, and how to handle it.
What is Kubernetes Container Exit Code 137?
Exit code 137 is a signal sent by the operating system to indicate that a process has been terminated due to a specific reason. In the context of Kubernetes, when a container exits with this code, it means that the container runtime has received a SIGKILL signal from the operating system.
Causes of Exit Code 137 in Kubernetes
SIGKILL signals are sent by the operating system under specific circumstances. Here are a few common reasons why a container might receive a SIGKILL and exit with code 137:

- Resource Exhaustion: The container may have run out of memory or CPU, causing the operating system to terminate it.
- OOM Killer: The Linux Out-Of-Memory (OOM) killer is a mechanism that terminates processes when the system is running out of memory. If your container is using too much memory, the OOM killer might terminate it, resulting in exit code 137.
- Docker's Default Behavior: Docker, a popular container runtime, has a default behavior of sending a SIGKILL to containers that have been running for more than 120 seconds and have not written anything to the stdout or stderr.
How to Handle Kubernetes Container Exit Code 137
If your container is exiting with code 137, it's essential to understand why. Here are some steps you can take to diagnose and handle the issue:
- Check Resource Usage: Use tools like `kubectl top pod` to monitor your pod's resource usage. If the container is consistently using a high amount of memory or CPU, you might need to request more resources for your pod.
- Investigate OOM Killer Events: Check the Kubernetes events for your pod. If the OOM killer has terminated your container, you should see an event with a message like "OOMKilled".
- Adjust Docker's Default Behavior: If you're using Docker as your container runtime, you can adjust the default behavior of sending a SIGKILL after 120 seconds. You can do this by setting the `oom_score_adj` value in your Dockerfile.
Conclusion
Kubernetes container exit code 137 is a signal that your container has been terminated due to a SIGKILL. Understanding the causes and handling this exit code can help you maintain the health and stability of your Kubernetes clusters. By monitoring resource usage, investigating OOM killer events, and adjusting container runtime behavior, you can effectively manage containers exiting with code 137.
























