Reputation: 13610
What is the kubernetes
cli
command that will list all nodes with state "Ready" except master node(s) ?
Upvotes: 2
Views: 2345
Reputation: 13610
Answer:
$ kubectl get nodes --selector '!node-role.kubernetes.io/master' --output jsonpath="{.items[?(@.status.conditions[-1].type=='Ready')].status.conditions[-1].type}"
Explenation:
Selector flag --selector '!node-role.kubernetes.io/master'
excludes all nodes that does not match node-role.kubernetes.io/master
label.
Output flag --output jsonpath="{.items[?(@.status.conditions[-1].type=='Ready')].status.conditions[-1].type}"
matches nodes, which last conditions is in Ready state - this turns out to be status of KubeletReady.
Edit: More elegant solution
$ kubectl get nodes --selector '!node-role.kubernetes.io/master' --output jsonpath="{range .items[?(@.status.conditions[-1].type=='Ready')]}{.metadata.name} {.status.conditions[-1].type}{'\n'}{end}"
Upvotes: 3