Anyone here knows how to list labels on a node (or any other k8s resource) each . . .

Neelesh Korade:
Anyone here knows how to list labels on a node (or any other k8s resource) each on a separate line using -o=jsonpath expression?

Konrad:
Something like this? kubectl get node (NODE_NAME) -o json | jq .metadata.labels

Neelesh Korade:
This needs installation of jq . I was wondering if there is a way to do this with the kubectl native jsonpaath support

Neelesh Korade:
Thanks though

Konrad:
kubectl get node node01 -o=jsonpath='{.metadata.labels}' this would be the basic usage I guess.

David Banks:

kubectl get nodes  -o=jsonpath='{range .items[*]}{.metadata.labels}{"\n"}{end}'

That will get you a list of labels for each node on a separate line, but if there are multiple labels per node, they’ll be on the same line for that node. If there is a way to iterate a dictionary instead of just a list, I don’t know how to do it.