<p>I have an init container that do some stuff that needs for the main container to run correctly, like creating some directories and a liveness probe that may fail if one of these directories were deleted. When the pod is restarted due to fail of liveness probe I expect that init container is also being restarted, but it won't.</p>
<p>This is what kubernetes documentation says about this:</p>
<p><code>If the Pod restarts, or is restarted, all init containers must execute again.</code>
<a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/init-containers/</a></p>
<p>Easiest way to prove this behavior was to use the example of the pod from k8s documentation, add a liveness probe that always fails and expect that init container to be restarted, but again, it is not behaving as expected.</p>
<p>This is the example I'm working with:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  restartPolicy: Always
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo &quot;App started at $(date)&quot; &amp;&amp; tail -f /dev/null']
    livenessProbe:
      exec:
        command:
        - sh
        - -c
        - exit 1
      initialDelaySeconds: 1
      periodSeconds: 1
  initContainers:
  - name: myapp-init
    image: busybox:1.28
    command: ['/bin/sh', '-c', 'sleep 5 &amp;&amp; echo &quot;Init container started at $(date)&quot;']
</code></pre>
<p>Sleep and date command are there to confirm that init container was restarted.</p>
<p>The pod is being restarted:</p>
<pre><code>NAME            READY   STATUS    RESTARTS   AGE
pod/myapp-pod   1/1     Running   4          2m57s
</code></pre>
<p>But from logs it's clear that init container don't:</p>
<pre><code>$ k logs pod/myapp-pod myapp-init
Init container started at Thu Jun 16 12:12:03 UTC 2022

$ k logs pod/myapp-pod  myapp-container
App started at Thu Jun 16 12:14:20 UTC 2022
</code></pre>
<p>I checked it on both <strong>v1.19.5</strong> and <strong>v1.24.0</strong> kubernetes servers.</p>
<p>The question is how to force the init container to restart on pod restart.</p>

vladtf
<p>The restart number refers to <strong>container</strong> restarts, not <strong>pod</strong> restarts.</p>
<p>init container need to run only once in a pos lifetime, and you need to design your containers like that, you can read this <a href="https://github.com/kubernetes/community/pull/2342" rel="nofollow noreferrer">PR</a>, and especially this <a href="https://github.com/kubernetes/community/pull/2342#issuecomment-983558850" rel="nofollow noreferrer">comment</a></p>
