Home > Mobile >  For Kubernetes pods how to find cause of exit code 2
For Kubernetes pods how to find cause of exit code 2

Time:12-07

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

I checked details in kubectl describe pod command and found that pod 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 cause of exit code 2.

Thanks in advance.

CodePudding user response:

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.

CodePudding user response:

You can get logs with

kubectl logs my-pod  

Post output here if you can't fix it.

  • Related