Understanding Kubernetes Exit Code 137 Error
When managing Kubernetes clusters, you might encounter an exit code 137 error, which can be puzzling and disruptive. This error typically occurs when a container is terminated due to a system resource issue. Let's delve into the details of this error, its causes, and how to troubleshoot it.
What is Kubernetes Exit Code 137?
Exit code 137 is a standard Unix/Linux error code that indicates a process has been terminated due to receiving a SIGKILL signal. In the context of Kubernetes, this means that the container runtime has sent a SIGKILL to one of your containers, causing it to exit with this error code.
Causes of Kubernetes Exit Code 137
The most common cause of exit code 137 in Kubernetes is running out of system resources, such as memory or CPU. Here are some specific scenarios that might trigger this error:

- Out of Memory (OOM) Killer: When a node runs out of memory, the Linux kernel's OOM killer starts terminating processes to free up memory. If your container is the one selected for termination, it will receive a SIGKILL and exit with code 137.
- Container Resource Limits: If you've set resource limits on your containers and they're consistently hitting these limits, it could lead to SIGKILL being sent when the container exceeds its allocated resources.
- Node Resource Pressure: High resource usage on the node itself can also lead to SIGKILL being sent to containers. This can happen due to system daemons, other containers, or even the kubelet itself consuming too many resources.
Troubleshooting Kubernetes Exit Code 137
When you encounter an exit code 137 error, follow these steps to troubleshoot the issue:
- Check the container's logs for any indications of resource exhaustion or other issues that might have led to the SIGKILL.
- Inspect the node's resource usage to see if there's high memory or CPU usage that could be causing the OOM killer to trigger. You can use commands like
kubectl top nodeor check the node's resource metrics in your cluster's monitoring system. - Review your container's resource requests and limits to ensure they're appropriate for the workload. You might need to adjust these values or set resource quotas on the namespace to prevent resource contention.
- If the issue persists, consider using tools like the Kubernetes Event-QOS (Quality of Service) feature or the Eviction API to manage resource usage and prevent containers from being terminated due to resource pressure.
Preventing Kubernetes Exit Code 137 Errors
To minimize the likelihood of encountering exit code 137 errors, follow these best practices:
- Monitor your cluster's resource usage to identify potential bottlenecks and adjust resources as needed.
- Set appropriate resource requests and limits for your containers to prevent them from consuming too many resources.
- Use Horizontal Pod Autoscaler (HPA) to automatically scale your deployments based on resource usage or custom metrics.
- Consider using resource quotas to limit the amount of resources that can be consumed by a namespace or a specific deployment.
By understanding the causes of Kubernetes exit code 137 errors and implementing these best practices, you can minimize their occurrence and maintain the stability of your Kubernetes clusters.























