Kubectl get JSON extracting

10/1/2021

I'm looking to pull out json information from a yaml file in kubernetes to specifically get the version of the image I'm using. Any help would be awesome.

command I'm using right now is

kubectl get statefulset -n namespace -o=jsonpath='{$.spec.template.spec.initcontainers[:1].image}'
-- ChawleeJay
kubectl
kubernetes

2 Answers

10/1/2021

Did you try using item?

-o jsonpath='{.items[*].spec.template.spec.initcontainers[:1].image}'
-- Bimal
Source: StackOverflow

10/5/2021

This was the solution:

kubectl get statefulset -n namespace -o=jsonpath='{$.spec.template.spec.containers[*].image}'

This also worked:

kubectl get statefulset -n namespace -o=jsonpath='{$.spec.template.spec.containers[:1].image}'
-- ChawleeJay
Source: StackOverflow