Johnny Gladwin
Johnny Gladwin

Reputation: 21

Automate the way to get the nodes that are ready

newbie here . I am trying to automate the way to get the nodes that are ready using the following script:

until kubectl get nodes | grep -m 2 "Ready"; do sleep 1 ; done

Is there a better way to do this, specifically i am looking for a way to do this without having to specify the node number?

Upvotes: 0

Views: 513

Answers (2)

Jakub
Jakub

Reputation: 8840

Basing on the official documentation

You can check your ready nodes by using this command:

JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \
 && kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"

You don't need to specify number of nodes in your command, just use it like this:

until kubectl get nodes | grep -i "Ready"; do sleep 1 ;  done

Upvotes: 0

Kamol Hasan
Kamol Hasan

Reputation: 13556

To get the names of all Ready nodes, use

$ kubectl get nodes -o json | jq -r '.items[] | select(.status.conditions[].type=="Ready") | .metadata.name '

master-0
node-1
node-3
node-x

Upvotes: 1

Related Questions