<p>In my setup I have two Pods. Each running a single container with busybox image.</p>
<p>I want to parse Pod name and its container's image name using Kubectl. First I tried to get these fields individually. That works fine. Then I tried to combine 'Pod name' with 'dns policy' field. And that also works. But if I try to combine the 'Pod name' and 'container image' fields, then I am getting the error.</p>
<p>Could you please help me understand why I am getting error with final command?</p>
<p>Thanks,</p>
<pre><code>test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath=&quot;{.items[*].spec.containers[*].image}&quot;
busybox busybox

test-cloud@user1-c1-cp1:~$
test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath=&quot;{.items[*]['.metadata.name']}&quot;
b2 b4

test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath=&quot;{.items[*]['.metadata.name', '.spec.dnsPolicy']}&quot;
b2 b4 ClusterFirst ClusterFirst

test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath=&quot;{.items[*]['.metadata.name}&quot; '.spec.containers[*].image']}
error: error parsing jsonpath {.items[*]['.metadata.name', '.spec.containers[*].image']}, invalid array index '.spec.containers[*
'''


</code></pre>

manish sehgal
<p>I would try to keep it simple by using <code>custom-columns</code>:</p>
<pre><code>kubectl get pod -o custom-columns=&quot;POD-NAME&quot;:.metadata.name,&quot;NAMESPACE&quot;:.metadata.namespace,&quot;CONTAINER-IMAGES&quot;:.spec.containers[*].image,&quot;DNS-POLICY&quot;:.spec.dnsPolicy
POD-NAME   NAMESPACE   CONTAINER-IMAGES   DNS-POLICY
bar        default     nginx              ClusterFirst
foo        default     nginx              ClusterFirst
zoo        default     nginx,ubuntu       ClusterFirst
</code></pre>
<p>Using <code>jsonpath</code>:</p>
<pre><code>kubectl get pod -o jsonpath='{range .items[*]}{.metadata.name},{.spec.containers[*].image},{.spec.dnsPolicy}{&quot;\n&quot;}{end}'
bar,nginx,ClusterFirst
foo,nginx,ClusterFirst
zoo,nginx ubuntu,ClusterFirst
</code></pre>
