Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Kubernetes pods how to find cause of exit code 2

I have pods that are of kind Cronjob running in parallel. They complete their task and run again after a fixed interval of 20 minutes as per the cron expression. I noticed that some pods are restarting 2-3 times before completing their task.

I checked for details with the kubectl describe pod command and found that the pods terminate with exit code 2 when it restart due to some error:

Last State:     Terminated
      Reason:       Error
      Exit Code:    2

I searched about exit code 2 and found that it is misuse of a shell builtin commands. How I can find which shell builtin is misused? How to debug the cause of exit code 2?

like image 749
anujprashar Avatar asked Oct 18 '25 13:10

anujprashar


1 Answers

An exit code of 2 indicates either that the application chose to return that error code, or (by convention) there was a misuse of a shell built-in. Check your pod’s command specification to ensure that the command is correct. If you think it is correct, try running the image locally with a shell and run the command directly.

Refer to this link for more information.

like image 176
Fariya Rahmat Avatar answered Oct 20 '25 02:10

Fariya Rahmat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!