Home > Mobile >  how to list the kubernetes pod which has CharDevice in it?
how to list the kubernetes pod which has CharDevice in it?

Time:04-22

how to list the Kubernetes pod which has CharDevice in it ?

I could able to get the pod with CharDevice, but need to print the pod name only

kubectl get pod -o jsonpath='{spec.volumes.hostPath.type=="CharDevice"}'

CodePudding user response:

You can get json first and use jq to get desired result :

kubectl get pod -o json |
jq -r '.items[]|select(any(.spec.volumes[];.hostPath.type=="CharDevice")).metadata.name'

CodePudding user response:

I think the filter/parsing you are expecting is not possible using jsonpath supplied with Kubectl. However, you can use go-template if you want to do it with kubectl only without using any other tool:

kubectl get pod -A -o  go-template='{{range $index, $element := .items}}{{range $key, $vol := .spec.volumes}}{{range $sk ,$sv := .hostPath}}{{if (eq $sv "CharDevice") }}{{$element.metadata.name}}{{"\n"}}{{end}}{{end}}{{end}}{{end}}'
  • Related