Komodor is a Kubernetes management platform that empowers everyone from Platform engineers to Developers to stop firefighting, simplify operations and proactively improve the health of their workloads and infrastructure.
Proactively detect & remediate issues in your clusters & workloads.
Easily operate & manage K8s clusters at scale.
Reduce costs without compromising on performance.
Empower developers with self-service K8s troubleshooting.
Simplify and accelerate K8s migration for everyone.
Fix things fast with AI-powered root cause analysis.
Explore our K8s guides, e-books and webinars.
Learn about K8s trends & best practices from our experts.
Listen to K8s adoption stories from seasoned industry veterans.
The missing UI for Helm – a simplified way of working with Helm.
Visualize Crossplane resources and speed up troubleshooting.
Validate, clean & secure your K8s YAMLs.
Navigate the community-driven K8s ecosystem map.
Kubernetes 101: A comprehensive guide
Expert tips for debugging Kubernetes
Tools and best practices
Kubernetes monitoring best practices
Understand Kubernetes & Container exit codes in simple terms
Exploring the building blocks of Kubernetes
Cost factors, challenges and solutions
Kubectl commands at your fingertips
Understanding K8s versions & getting the latest version
Rancher overview, tutorial and alternatives
Kubernetes management tools: Lens vs alternatives
Troubleshooting and fixing 5xx server errors
Solving common Git errors and issues
Who we are, and our promise for the future of K8s.
Have a question for us? Write us.
Come aboard the K8s ship – we’re hiring!
Hear’s what they’re saying about Komodor in the news.
Exit codes are used by container engines, when a container terminates, to report why it was terminated.
If you are a Kubernetes user, container failures are one of the most common causes of pod exceptions, and understanding container exit codes can help you get to the root cause of pod failures when troubleshooting.
The most common exit codes used by containers are:
Below we’ll explain how to troubleshoot failed containers on a self-managed host and in Kubernetes, and provide more details on all of the exit codes listed above.
This is part of an extensive series of guides about Observability.
To better understand the causes of container failure, let’s discuss the lifecycle of a container first. Taking Docker as an example – at any given time, a Docker container can be in one of several states:
When a container reaches the Exited status, Docker will report an exit code in the logs, to inform you what happened to the container that caused it to shut down.
Itiel Shwartz
Co-Founder & CTO
In my experience, here are tips that can help you better handle exit codes in containers and Kubernetes:
Set appropriate resource limits to prevent OOMKilled (exit code 137) and other resource-related issues.
Implement these probes to detect and respond to container failures automatically.
Configure restart policies to handle transient issues without manual intervention.
Collect and analyze logs for all containers to quickly identify the root cause of failures.
Implement health checks in your containerized applications to detect and resolve issues proactively.
Below we cover each of the exit codes in more detail.
Exit Code 0 is triggered by developers when they purposely stop their container after a task completes. Technically, Exit Code 0 means that the foreground process is not attached to a specific container.
What to do if a container terminated with Exit Code 0?
Exit Code 1 indicates that the container was stopped due to one of the following:
What to do if a container terminated with Exit Code 1?
Exit Code 125 means that the command is used to run the container. For example docker run was invoked in the system shell but did not execute successfully. Here are common reasons this might happen:
docker run
docker run --abcd
What to do if a container terminated with Exit Code 125?
docker start
Exit Code 126 means that a command used in the container specification could not be invoked. This is often the cause of a missing dependency or an error in a continuous integration script used to run the container.
What to do if a container terminated with Exit Code 126?
Exit Code 127 means a command specified in the container specification refers to a non-existent file or directory.
What to do if a container terminated with Exit Code 127?
Same as Exit Code 126, identify the failing command and make sure you reference a valid filename and file path available within the container image.
Learn more in our detailed guide to exit code 127.
Exit Code 128 means that code within the container triggered an exit command, but did not provide a valid exit code. The Linux exit command only allows integers between 0-255, so if the process was exited with, for example, exit code 3.5, the logs will report Exit Code 128.
exit
exit code 3.5
What to do if a container terminated with Exit Code 128?
Exit Code 134 means that the container abnormally terminated itself, closed the process and flushed open streams. This operation is irreversible, like SIGKILL (see Exit Code 137 below). A process can trigger SIGABRT by doing one of the following:
Calling the abort() function in the libc libraryCalling the assert() macro, used for debugging. The process is then aborted if the assertion is false.
abort()
libc
assert()
What to do if a container terminated with Exit Code 134?
Exit Code 137 means that the container has received a SIGKILL signal from the host operating system. This signal instructs a process to terminate immediately, with no grace period. This can be either:
docker kill
kill -9
docker inspect
OOMKilled
guide to exit code 137.
What to do if a container terminated with Exit Code 137?
Learn more in our detailed guide to the SIGKILL signal >>
Exit Code 139 means that the container received a SIGSEGV signal from the operating system. This indicates a segmentation error – a memory violation, caused by a container trying to access a memory location to which it does not have access. There are three common causes of SIGSEGV errors:
What to do if a container terminated with Exit Code 139?
Learn more in our detailed guide to the SIGSEGV signal >>
Exit Code 143 means that the container received a SIGTERM signal from the operating system, which asks the container to gracefully terminate, and the container succeeded in gracefully terminating (otherwise you will see Exit Code 137). This exit code can be:
docker stop
docker-compose
What to do if a container terminated with Exit Code 143?
Check host logs to see the context in which the operating system sent the SIGTERM signal. If you are using Kubernetes, check the kubelet logs to see if and when the pod was shut down.
In general, Exit Code 143 does not require troubleshooting. It means the container was properly shut down after being instructed to do so by the host.
Learn more in our detailed guide to the SIGTERM signal >>
Same as Exit Code 126 above, identify the failing command and make sure you reference a valid filename and file path available within the container image.
When you see exit code 255, it implies the main entrypoint of a container stopped with that status. It means that the container stopped, but it is not known for what reason.
What to do if a container terminated with Exit Code 255?
Whenever containers fail within a pod, or Kubernetes instructs a pod to terminate for any reason, containers will shut down with exit codes. Identifying the exit code can help you understand the underlying cause of a pod exception.
You can use the following command to view pod errors: kubectl describe pod [name]
kubectl describe pod [name]
The result will look something like this:
Containers: kubedns: Container ID: ... Image: ... Image ID: ... Ports: ... Host Ports: ... Args: ... State: Running Started: Fri, 15 Oct 2021 12:06:01 +0800 Last State: Terminated Reason: Error Exit Code: 255 Started: Fri, 15 Oct 2021 11:43:42 +0800 Finished: Fri, 15 Oct 2021 12:05:17 +0800 Ready: True Restart Count: 1
Use the Exit Code provided by kubectl to troubleshoot the issue:
kubectl
exit(-1)
Refer to the relevant section above to see how to troubleshoot the container for each exit code.
As a Kubernetes administrator or user, pods or containers terminating unexpectedly can be a pain and can result in severe production issues. The troubleshooting process in Kubernetes is complex and, without the right tools, can be stressful, ineffective, and time-consuming.
Some best practices can help minimize the chances of container failure affecting your applications, but eventually, something will go wrong—simply because it can.
This is the reason why we created Komodor, a tool that helps dev and ops teams stop wasting their precious time looking for needles in (hay)stacks every time things go wrong.
Acting as a single source of truth (SSOT) for all of your k8s troubleshooting needs, Komodor offers:
Together with our content partners, we have authored in-depth guides on several other topics that can also be useful as you explore the world of observability.
Authored by Lumigo
Authored by Exabeam
Share:
How useful was this post?
Click on a star to rate it!
Average rating 5 / 5. Vote count: 7
No votes so far! Be the first to rate this post.
and start using Komodor in seconds!