Automate the way to get the nodes that are ready

9/11/2019

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?

-- Johnny Gladwin
kubectl
kubernetes
kubernetes-pod

2 Answers

9/11/2019

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
-- Kamol Hasan
Source: StackOverflow

9/11/2019

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
-- jt97
Source: StackOverflow