Find All Nodeselectors in a Cluster

163 Views Asked by At

I have a big cluster on Openshift Platform. I want to find all the projects or pods that are using NodeSelector. Is there a command for that? How can I make a list of all the projects with NodeSelectors?

I have a command for listing all the services using nodeport. But I could not do it for nodeSelector.

1

There are 1 best solutions below

2
On BEST ANSWER

You can use jq for that:

$ kubectl get pod -A -o json \
  | jq -r '.items[] | select(.spec.nodeSelector != null) | .metadata.namespace + "/" + .metadata.name + ", " + (.spec.nodeSelector | tostring)'

will return something like

<namespace>/<podname>, {"key": "value"}

for all pods that are using a node selector.