Running pods until it finishes and exits:

The below pod Job - runs until it completes its tasks, and then exits either with a success or a failure "exit" code. 

We could see that by checking the "exit" code of a pod, using the below command:


Exit code : "0", means that the pod exited successfully.

If a pod fails, it is restarted until the limit of "restarts" is reached. 
We could set this limit using the following parameter in the Job's YAML file: "backoffLimit".

Remark:

We can't use the default "restartPolicy: Always" with Jobs.

The restartPolicy defines the action Kubernetes takes when a container's process finishes its task.

Below we have an example of a YAML file for a Job:


We could see that the above pod have completed its task - command - and exited, using the below command:


We could also check the status of our Job using the below command:


Brando Sabatini and Ikbal C ©. Powered by Blogger.