我想遍历节点中的节点名称
kubectl get nodes
命令并回显Bash
中的名称。
答案 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 = ...