<p>I have a <code>pod</code> which embed an <code>initContainer</code> named <code>initdb</code>. Is there a <code>kubectl</code> command which returns <code>true</code> if <code>initdb</code> is started or else <code>false</code>? I need it to display logs of <code>initdb</code> in Github Action CI (<code>kubectl log &lt;pod&gt; -c initdb</code> crashes if <code>initd</code> is not started yet).</p>

Fabrice Jammes
<p>If you have a single init container in the Pod, you could so something like the following:</p>
<pre><code>k get pod pod-name --output=&quot;jsonpath={.status.initContainerStatuses[0].ready}&quot;
</code></pre>
<p>This will return true if the init container is in status Ready, but this means only that the init container is ready, it could be already terminated (because it completed the execution) or still running. I'm not completely sure but if an init container is ready, requesting its logs should work without errors)</p>
<p>You can use jsonpath to select specific sections of Pods definitions exactly for the scope of automating certain checks.</p>
<p>To see the full definition of your Pod, just use:</p>
<pre><code>k get pod pod-name -oyaml
</code></pre>
<p>and maybe select what you are interested from there. If you want to wait until the init container is terminated or started, you could check its <code>state</code> section which explains the current state in detail and basically create a more finer check on what you are expecting to see.</p>
