In my setup I have two Pods. Each running a single container with busybox image.
I want to parse Pod name and its container’s image name using Kubectl. First I tried to get these fields individually. That works fine. Then I tried to combine ‘Pod name’ with ‘dns policy’ field. And that also works. But if I try to combine the ‘Pod name’ and ‘container image’ fields, then I am getting the error.
Could you please help me understand why I am getting error with final command?
Thanks,
test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath="{.items[*].spec.containers[*].image}"
busybox busybox
test-cloud@user1-c1-cp1:~$
test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath="{.items[*]['.metadata.name']}"
b2 b4
test-cloud@user1-c1-cp1:~$ k get pods -o jsonpath="{.items[*]['.metadata.name', '.spec.dnsPolicy']}"
b2 b4 ClusterFirst ClusterFirst
test-cloud@user1-c1-cp1:~$ k 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[*
'''
2
Answers
Thanks for the replies. While posted answers would work, I found below more suitable:
b2 b4, busybox busybox
I would try to keep it simple by using
custom-columns
:Using
jsonpath
: