<p>We have a multi pod container which consists of 2 pods. init container runs first and the actual container run. recently our init container job are failing due to which our deployment is getting failed. we need to get the init container logs post completion of the init container</p>
<p>is there way to do that ??</p>
<p>i know we can get the logs when init container is running but we need logs even after the init container job is comeplete</p>
<p>any solution , we are using jenkins for build and deploy</p>

Ganesh
<p>You can run the cmd:</p>
<pre><code>kubectl logs &lt;pod_name&gt; -c &lt;init_container_name&gt;
</code></pre>
<p>This will fetch the logs of the init container even after is finished running.</p>
<p>Just an example, for the below pod spec the <code>init-container</code> runs first (to completion) and just prints &quot;Hello world&quot;.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: main-container
    image: busybox
    command: [&quot;/bin/sh&quot;, &quot;-ec&quot;, &quot;while :; do echo '.'; sleep 5 ; done&quot;]
  initContainers:
  - name: init-container
    image: busybox
    command: ['sh', '-c', 'echo &quot;Hello world&quot;'] 
</code></pre>
<p>If I run this command:</p>
<pre><code>kubectl logs test-pod -c init-container
</code></pre>
<p>I get the output:</p>
<pre><code>Hello world
</code></pre>
<p>To get logs of all containers within a pod, you could use:</p>
<pre><code>kubectl logs &lt;pod_name&gt; --all-containers
</code></pre>
<p>Hope it helps!</p>
