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?
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
backoffLimit: 4
- number of retries before throwing error
completions: 3
- number of times to run