如何遍历kubectl的节点列表,并回显每个节点名称?

时间:2020-09-29 01:10:17

标签: bash kubernetes kubectl

我想遍历节点中的节点名称 kubectl get nodes命令并回显Bash中的名称。

1 个答案:

答案 0 :(得分:6)

kubectl-o标志下提供了各种过滤器。您可以使用kubectl --help查看列表。一种方法是使用for循环对其进行循环。

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

-o,--output ='':输出格式之一: json | yaml | wide | name | custom-columns = ... | custom-columns-file = ... | go-template = ... | go-template-file = ... | jsonpath = ... | jsonpath-file = ...