CKA: get pod name, namespace, and container image using jsonpath

In my minikube, I have 3 pods, 1 of the pods has 2 containers, so total of 4 containers. I want to get name of pod, namespace, and contianer image using jsonpath query, but it is failing.
$ k get pods
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 0 3d15h
log-app-dd9bfccf-58g6p 2/2 Running 0 3d22h
test-pod 1/1 Running 1 (4d1h ago) 6d3h

just to get name and namespace works:
$ kubectl get pods -o=jsonpath=“{.items[*][‘metadata.name’,‘metadata.namespace’]}”
busybox log-app-dd9bfccf-58g6p test-pod default default default

just to get the container image also works:
$ kubectl get pods -o=jsonpath=‘{.items[].spec.containers[].image}’
busybox busybox busybox nginx

But when I try to combine all the above in one command, it fails:
$ kubectl get pods -o=jsonpath=“{.items[][‘metadata.name’,‘metadata.namespace’,'spec.containers[].image’]}”
error: error parsing jsonpath {.items[][‘metadata.name’,‘metadata.namespace’,'spec.containers[].image’]}, invalid array index 'spec.containers[*

The problem here is getting past .spec.container, since the format you’re using won’t do that. I would use custom-columns instead, which has less tweaky syntax:

k get po -o custom-columns='N:.metadata.name,NS:.metadata.namespace,I:.spec.containers[].image'

Thanks Rob.
I changed the pod that had 2 containers to 1, thinking that could be the reason jsonpath was having issue and giving error, but the same error persist; hopefully this will not be a question on exam :slight_smile:

@akbar_aman
Also read this to better understand jsonpath.