<p>I have an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">Init Container</a> that does a database version check. If the database version check in the Init Container fails, the whole Deployment should fail immediately. But I still want the other Containers in the Pod to <code>restartPolicy=Always</code>.</p>

<p>However, Init Containers are</p>

<blockquote>
  <p>retried according to the Pod <code>restartPolicy</code></p>
</blockquote>

<p>It would be good if I could specify a different <code>restartPolicy</code> for the Init Container than the Deployment but that's not possible. <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="nofollow noreferrer">Lifecycle Hooks</a> wouldn't really work either as what you need for this use case is a <code>PreStart</code> hook.</p>

<p>Is there a good way to get Init Containers to fail fast?</p>

Everett Toews
<p>Would you like to spin a separate container, which will be checking db version and if succeeds, creates some artifact, like file <code>/tmp/db_version</code> on the host's drive and then you just add <strong>livenessProbe/readinessProbe</strong> to your main Deployment, which will be checking existence of the <code>/tmp/db_version</code>, e.g.</p>

<pre><code>livenessProbe:
      exec:
        command:
        - ls
        - /tmp/db_version
      initialDelaySeconds: 5
      periodSeconds: 5
</code></pre>

<p>Thus you'll be able to sideline <strong>restartPolicy</strong> of the db_version_check container and your main container.</p>
