how to list the number of ready nodes in a cluster which don't have a taint

11/10/2019

Want to list the number of ready nodes without any taint. I get the list of nodes using below query:

kubectl get nodes -o json|jq -jr '{.items[]|select(.spec.taints|not)|select(.status.conditions[].type=="Ready" and .status.conditions[].status="True")|.metadata.name+"\n"}'

This gives me below output

node01
node01

How to I get number of nodes instead of actual node names from this query ?

-- Naxi
kubernetes

1 Answer

11/24/2019

Use this for number of nodes with "No taint":

kubectl get nodes -o json | jq '.items[] | select(.spec.taints|not) | .metadata.name' | wc -l

Get number of nodes with "Ready" status and "No taint":

kubectl get nodes -o json|jq -r '.items[]|select(.status.conditions[].type=="Ready")|select(.spec.taints|not).metadata.name' | wc -l
-- kalgopa
Source: StackOverflow