1

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?

Eyal Levin
  • 16,271
  • 6
  • 66
  • 56
tobe
  • 1,671
  • 2
  • 23
  • 38

2 Answers2

1

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
  • 12,422
  • 5
  • 57
  • 67
1

backoffLimit: 4 - number of retries before throwing error

completions: 3 - number of times to run