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

cle*_*ent 1 bash kubernetes kubectl

我想循环遍历kubectl get nodes命令中的节点名称 并在Bash.

P..*_*... 6

kubectl-oflag下提供各种过滤器。您可以使用kubectl --help. 一种方法是使用 for 循环遍历它。

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

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