How do I extract multiple values from kubectl with jsonpath

9/14/2017

I've found jsonpath examples for testing multiple values but not extracting multiple values.

I want to get image and name from kubectl get pods.

this gets me name kubectl get pods -o=jsonpath='{.items[*].spec.containers[*].name}' | xargs -n 1

this gets me image kubectl get pods -o=jsonpath='{.items[*].spec.containers[*].image}' | xargs -n 1

but kubectl get pods -o=jsonpath='{.items[*].spec.containers[*].[name,image}' | xargs -n 2

complains invalid array index image - is there a syntax for getting a list of node-adjacent values?

-- navicore
jsonpath
kubectl
kubernetes

1 Answer

9/15/2017

Use below command to get name and image

kubectl get pods -ao jsonpath='{range .items[*]}{@.metadata.name}{" "}{@.spec.template.spec.containers[].image}{"\n"}{end}'

it will give output like below name image

-- Pawan Kumar
Source: StackOverflow