Can someone please let me know what's wrong with the first one. controlplane ~ . . .

infyniti:
Can someone please let me know what’s wrong with the first one.

controlplane ~ ➜ kubectl get pods -o=jsonpath="{.items[][‘metadata.name’, 'spec.containers[].image’]}
"error: error parsing jsonpath {.items[][‘metadata.name’, 'spec.containers[].image’]}, invalid array index 'spec.containers[*

controlplane ~ :heavy_multiplication_x: kubectl get pods -o=jsonpath=“{range .items[]}{.metadata.name}{‘\t’}{.spec.containers[].image}{‘\n’}{end}”
webapp-mysql-75dfdf859f-7xwxj mmumshad/simple-webapp-mysql
mysql mysql:5.6

ChengLim Teo:

$ kubectl get pods -o=jsonpath="{.items[*].metadata.name} {.items[*].spec.containers[*].image}"

ChengLim Teo:
or better… if you want search anything pod name start with “test-”

$ kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test("test-")).spec.containers[].image'

infyniti:
Thank you, I was just trying out the first command based on the official jsonpath documentation. It works to print containers, but fails when to print anything underneath containers. There is something i am doing wrong and cannot figure out.

controlplane ~ ➜ kubectl get pods -o=jsonpath=“{.items[*][‘metadata.name’, ‘spec.containers’]}”
webapp-mysql-75dfdf859f-7xwxj mysql [{“env”:[{“name”:“DB_Host”,“value”:“mysql-service”},{“name”:“DB_User”,“value”:“root”},{“name”:“DB_Password”,“value”:“paswrd”}],“image”:“mmumshad/simple-webapp-mysql”,“imagePullPolicy”:“Always”,“name”:“webapp-mysql”,“ports”:[{“containerPort”:8080,“protocol”:“TCP”}],“resources”:{},“terminationMessagePath”:“/dev/termination-log”,“terminationMessagePolicy”:“File”,“volumeMounts”:[{“mountPath”:“/var/run/secrets/kubernetes.io/serviceaccount”,“name”:“kube-api-access-zwhhx”,“readOnly”:true}]}] [{“env”:[{“name”:“MYSQL_ROOT_PASSWORD”,“value”:“paswrd”}],“image”:“mysql:5.6”,“imagePullPolicy”:“IfNotPresent”,“name”:“mysql”,“ports”:[{“containerPort”:3306,“protocol”:“TCP”}],“resources”:{},“terminationMessagePath”:“/dev/termination-log”,“terminationMessagePolicy”:“File”,“volumeMounts”:[{“mountPath”:“/var/run/secrets/kubernetes.io/serviceaccount”,“name”:“kube-api-access-p4x2t”,“readOnly”:true}]}]

ChengLim Teo:
another way is to use “range”

# Check which nodes are ready
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \
 && kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"

ChengLim Teo:
yet another way is to use “jq” if you spending too much time on this. For me “jq” is install everywhere