Lukasz Dynowski
Lukasz Dynowski

Reputation: 13610

How to get all nodes with status 'Ready' except master node(s)?

What is the kubernetes cli command that will list all nodes with state "Ready" except master node(s) ?

Upvotes: 2

Views: 2345

Answers (2)

Aakizone
Aakizone

Reputation: 325

$ kubectl get nodes --selector '!node-role.kubernetes.io/master'

Upvotes: -1

Lukasz Dynowski
Lukasz Dynowski

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

Related Questions