Jobs

Jobs have a much shorter lifecycle most Kubernetes resources, which are designed to maintain long-lived instances. They allow executing one or pods and ensuring that a minimum number of them complete successfully, and are ideal for modelling ad hoc or batch jobs.

apiVersion: batch/v1
kind: Job
metadata:
    name:
spec:
    template:
        spec:
            containers:
              - name:
                  image:
                  command:
                    - /something
                  restartPolicy: Never

Status

Success of a job is determined by a container's exit status. The behaviour to take on failure is determined by the pod's restartPolicy:

  • Always is incompatible, as successful completion should terminate the pod.
  • Failure allows the pod to restart and retry on failure.
  • Never causes the job to be marked as failed after the first failed execution.

Execution control

  • backoffLimit sets the maximum number of allowed retries (default 6).
  • activeDeadlineSeconds sets the maximum execution time.
  • parallelism sets the maximum number of pods that may be in the running state in a job at any time.
  • completions sets the number of pods which must complete successfully to consider the job completed.

Implementation

The job controller will reschedule a job upon interrupted execution.

Job objects are preserved upon completion, allowing clients to check the status of completed jobs. The status of the execution can be determined by looking at the exit status of the pods, which are preserved (along with their logs). Pods are deleted with the job.


Backlinks