<p>The best source for restart policies in Kubernetes I have found is this:</p>
<p><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>But it only lists the possible <code>restartPolicy</code> values and does not explain them.</p>
<p>What is the difference between <code>Always</code> and <code>OnFailure</code>? Mustn't the thing fail before it can be restarted?</p>

jonalv
<p><strong>Always</strong> means that the container will be restarted even if it exited with a zero exit code (i.e. successfully). This is useful when you don't care why the container exited, you just want to make sure that it is always running (e.g. a web server). This is the default.</p>

<p><strong>OnFailure</strong> means that the container will only be restarted if it exited with a non-zero exit code (i.e. something went wrong). This is useful when you want accomplish a certain task with the pod, and ensure that it completes successfully - if it doesn't it will be restarted until it does.</p>

<p><strong>Never</strong> means that the container will not be restarted regardless of why it exited. </p>

<p>These different restart policies basically map to the different controller types as you can see from <code>kubectl run --help</code>:</p>

<blockquote>
  <p>--restart="Always": The restart policy for this Pod.  Legal values [Always, OnFailure, Never].  If set to 'Always' a deployment is created for this pod, if set to 'OnFailure', a job is created for this pod, if set to 'Never', a regular pod is created. For the latter two --replicas must be 1.  Default 'Always'</p>
</blockquote>

<p>And the <a href="http://kubernetes.io/docs/user-guide/pod-states/#restartpolicy" rel="noreferrer">pod user-guide</a>:</p>

<blockquote>
  <p>ReplicationController is only appropriate for pods with RestartPolicy = Always. Job is only appropriate for pods with RestartPolicy equal to OnFailure or Never.</p>
</blockquote>
