Skip to content

Instantly share code, notes, and snippets.

@navicore
Last active January 24, 2024 17:25
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save navicore/624d3b6e8ba2a8edd3a5f8664d6dacc5 to your computer and use it in GitHub Desktop.
Save navicore/624d3b6e8ba2a8edd3a5f8664d6dacc5 to your computer and use it in GitHub Desktop.
for getting multiple kubernetes yaml fields from kubectl via jsonpath

get name and image and startTime

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

edited 10/2022 with .. and A suggestions

@ykfq
Copy link

ykfq commented May 22, 2020

For new versions kubectl, you'd like to use -Ao instead.

Use .. to search some deep nested keys and column -t for alignment:

kubectl get pods -o jsonpath='{range .items[*]}{@.metadata.name}{" "}{@..containers.image}{" "}{@.status.phase}{" "}{@..startTime}{"\n"}{end}' | column -t

@navicore
Copy link
Author

nice. thanks!

@joebowbeer
Copy link

{@..containers..image}

@uvaise-rocket
Copy link

Thank you . this helped in fetching multiple fields in a big json groupwise ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment