How to configure the restart times of Kubernetes Jobs?

3/20/2017

Now we're using Kubernetes to run users' tasks. We need the features of Kubernetes Jobs to restart the tasks when failure occurs.

But our users may submit the problematic applications which always exit with non-zore code. Kubernetes will restart this task over and over again.

Is is possible to configure the restart times about this?

-- tobe
jobs
kubernetes
kubernetes-jobs

2 Answers

3/20/2017

You can use the standard pod restart policy: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy

Unfortunately, only a policy of "Never" or "OnFailure" is allowed, so if you need to restart X times then fail, that's not possible.

Example:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    metadata:
      name: pi
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
-- jaxxstorm
Source: StackOverflow

1/11/2019

backoffLimit: 4 - number of retries before throwing error

completions: 3 - number of times to run

-- user10899925
Source: StackOverflow