<p>I am looking to list all the containers in a pod in a script that gather's logs after running a test.  <code>kubectl describe pods -l k8s-app=kube-dns</code> returns a lot of info, but I am just looking for a return like:</p>

<pre><code>etcd
kube2sky
skydns
</code></pre>

<p>I don't see a simple way to format the describe output.  Is there another command?  (and I guess worst case there is always parsing the output of describe).</p>

<h1>Answer</h1>

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

<h1>Explanation</h1>

<p>This gets the JSON object representing the pod. It then uses kubectl's <a href="https://kubernetes.io/docs/user-guide/jsonpath/" rel="noreferrer">JSONpath</a> to extract the name of each container from the pod.</p>
