<p>A solution to retrieve all containers running in a pod is to run <code>kubectl get pods POD_NAME_HERE -o jsonpath={.spec.containers[*].name}</code>, however this command line does not provide the init containers.</p>

<p>Is there a way to cleanly retrieve all containers running in a pod, including init containers?</p>

<p>[edit] as svenwltr noted, on Kubernete 1.6.0 or higher, it is possible to retrieve the init container with <code>kubectl get pods POD_NAME_HERE -o jsonpath={.spec.initContainers[*].name}</code> and all containers can be retrieved with <code>kubectl get pod POD_NAME_HERE -o jsonpath="{.spec['containers','initContainers'][*].name}"</code>. However, this is not a valid workaround for lower versions of Kubernetes where <code>.spec.initContainers</code> isn't implemented yet.</p>

<p>The init containers are stored in <code>spec.initContainers</code>:</p>

<pre><code>kubectl get pods POD_NAME_HERE -o jsonpath={.spec.initContainers[*].name}
</code></pre>

<p>You can display both with a bit of <a href="https://kubernetes.io/docs/user-guide/jsonpath/" rel="noreferrer">JSONPath magic</a>:</p>

<pre><code>kubectl get pod POD_NAME_HERE -o jsonpath="{.spec['containers','initContainers'][*].name}"
</code></pre>

<hr>

<p>Before Kubernetes 1.6 the init containers were stored in <code>.metadata.annotations."pod.beta.kubernetes.io/init-containers"</code>. So it should be possible to get them via:</p>

<pre><code>kubectl get pods POD_NAME_HERE -o jsonpath='{metadata.annotations."pod.beta.kubernetes.io/init-containers".[*].name}'
</code></pre>

<p>Unfortunately I cannot test this, because I don't have a cluster with this version. Also joining containers and init containers into a single command looks a bit harder this way.</p>
