Search code examples
kuberneteskubernetes-pod

How to exclude taint nodes from outputs in kubectl get nodes?


I try to check how many nodes are ready (not including nodes tainted NoSchedule) and write the number to text file output.txt.

Could you give me any advice?


Solution

  • I believe that kubectl get nodes doesn't show taints, so you can't just filter with grep. In that case you can set the output as json and use jq (or yaml and use yq) to process it:

    kubectl get nodes -o json | jq -c '.items[].spec.taints' | grep -v NoSchedule | wc -l > output.txt
    

    -c option in jq is to output each element in a single line, instead of pretty printing it, in case you have multiple taints. The rest has already been explained in Abdennour TOUMI's answer