0

For example:

command kgp -o jsonpath='{range .items[]}{range @.spec.containers[]}{@.name}{"\t"}{.items[].metadata.name}{"\n"}{end}{"\n"}{end}'

output

  • nginx
  • istio-proxy
  • sidecar-1

expected output

  • nginx default
  • istio-proxy default
  • sidecar-1 default
kabilan
  • 11
  • 3

2 Answers2

0

I think you want to print the pattern podname namespace. Is that right? Then you have to change .items[].metadata.name to .items[].metadata.namespace.

zer0
  • 2,153
  • 10
  • 12
  • kgp -o jsonpath='{range .items[]}{range @.spec.containers[*]}{@.name}{"\t"}{.items[].metadata.name}{"\n"}{end}{"\n"}{end}' I actually wanted to fetch the sidecar container name with namespace in each row – kabilan Aug 05 '22 at 13:49
0

Try this:

kubectl get po -o jsonpath='{range .items[*]}{@.spec.containers[*].name}{" "}{@.metadata.namespace}{"\n"}{end}'
ericfossas
  • 1,511
  • 8
  • 12
  • I am trying to get a o/p in some format. i.e To fetch the resource request and limits of each container, which shall have the pod name, namespace, container name and its request and limit details – kabilan Aug 05 '22 at 13:28
  • I used the below command **kubectl get pods -o jsonpath='{range .items[]}{@.metadata.name}{","}{@.metadata.namespace}{","}{range @.spec.containers[*]}{@.name}{","}{@.resources.requests.cpu}{","}{@.resources.limits.cpu}{","}{@.resources.requests.memory}{","}{@.resources.limits.memory}{"\n"}{end}{"\n"}{end}'** I tried with the above command, but only for the 1st entry the o/p is right, for other entries, its pod name and its namespace is missing in the first 2 columns. – kabilan Aug 05 '22 at 13:31
  • if i answered your original question, please accept it. ask your new question in a new post and i'll help you there. please ask the question about the end result you are trying to achieve though and not what you think the solution will be. see this: https://xyproblem.info/ – ericfossas Aug 05 '22 at 17:48