In this article, we will see how to solve kubernetes pod CrashLoopBackOff with Exit Code 1 error. If you are working on Kubernetes Cluster from quite some time then I am sure you must have seen this CrashLoopBackOff status very frequently. This error is so common that sometimes it is very difficult to find the exact root cause of this error especially in a situation where you have multiple pods in a cluster showing same error and each of the them is due to different reasons. So in this situation you need to always look for exit code in pod description to narrow down the problem.
In my case, I faced similar problem when I was trying to deploy one application in my kubernetes cluster where I noticed pod showing in
CrashLoopBackOff status with
Exit Code 1 error in the pod description post deployment. This exit code helped me finding the root cause of
CrashLoopBackOff error which I am going to explain below in great detail.
Solved "Kubernetes Pod CrashLoopBackOff with Exit Code 1" Error
Also Read: Solved "Error while dialing dial unix /var/run/dockershim.sock"
As I was explaining, after deploying my application to kubernetes cluster when I tried to check the status of pods using
kubectl get pods command then I noticed
CrashLoopBackOff status on the output as you can see below.
[cyberithub@node1]$ kubectl get pods NAME READY STATUS RESTARTS AGE app-fscm-66b6c48dd5-8n9sh 0/1 CrashLoopBackOff 21 2h app-hcm-74d6a52ee7-q72cf 1/1 Running 0 13d app-portal-51g9d36ab6-z8tgd 1/1 Running 0 41d
To further check this
CrashLoopBackOff error, I tried to describe the pod by using
kubectl describe pod app-fscm-66b6c48dd5-8n9sh command as shown below. Here I have noticed that the
Reason is showing as
Exit Code is showing as
[cyberithub@node1]$ kubectl describe pod app-fscm-66b6c48dd5-8n9sh ............................... State: Waiting Reason: CrashLoopBackOff Last State: Terminated Reason: Error Exit Code: 1 ................................
The above exit code basically means the application has failed to start within the process which in turn causing failure of container creation and hence pod is not coming into running state. You can also notice that the restart count will keep on increasing. It is simply because every time application fails to start, kubernetes will restart that pod to bring up the application and hence restart count will keep on increasing until the pod comes to the running state.
So it is important to understand here that to fix the above error, you need to fix the issue with the application which you are trying to deploy in the cluster. In my case, I have identified the problem in my application and fixed it. Then I tried again to deploy that application and this time I noticed that it got deployed successfully as you can see below.
[cyberithub@node1]$ kubectl get pods NAME READY STATUS RESTARTS AGE app-fscm-66b6c48dd5-k6d4e 1/1 Running 0 77s app-hcm-74d6a52ee7-q72cf 1/1 Running 0 13d app-portal-51g9d36ab6-z8tgd 1/1 Running 0 41d
While the above solution worked for me because it was issue with only one pod. Sometimes it is possible that the same error can occur for multiple pods in a cluster. In that case, it is possible that there is no problem with your application but actually on the cluster node. To check that, you can run
kubectl get nodes -o wide command as shown below and verify all the nodes are working fine.
[cyberithub@node1]$ kubectl get nodes -o wide
Hope above given solution would be enough to solve your
Exit Code 1 error as well. Still if you see the above solution does not work for you then I would request you to please let me know your feedback in the comment box so that we can work together to solve your problem as well.