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

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

<p>Is is possible to configure the restart times about this? </p>

<p>You can use the standard pod restart policy: <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy</a></p>

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

<p>Example:</p>

<pre><code>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
</code></pre>
