anujprashar
anujprashar

Reputation: 6335

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?

Upvotes: 4

Views: 20737

Answers (2)

Fariya Rahmat
Fariya Rahmat

Reputation: 3260

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.

Upvotes: 3

Christoph Fischer
Christoph Fischer

Reputation: 105

You can get logs with

kubectl logs my-pod  

Post output here if you can't fix it.

Upvotes: 0

Related Questions