kubernetesopenshiftredhatkubernetes-nodeportnodeselector

Find All Nodeselectors in a Cluster


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.


Solution

  • 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.