How to loop over kubectl's node list, echoing each node name?

Viewed 1525

I want to be loop through the node names from the kubectl get nodes command and echo the names in Bash.

1 Answers

kubectl provides various filters under -o flag. you can see the list using kubectl --help. One of the ways is to loop over it using for loop.

for node in $(kubectl get nodes -o name);
do
  echo "     Node Name: ${node##*/}"
  echo "Type/Node Name: ${node}"
  echo  
done

-o, --output='': Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...

Related