|NO.Z.00021|——————————|^^ 标准 ^^|——|KuberNetes&标准.V20|——|常用操作.V06|格式化输出|

一、格式化输出:以特定格式将详细信息输出到终端窗口可以将-o--output参数添加到支持的kubectl命令

输出格式

描述

-o=custom-columns=<spec>

使用逗号分隔的自定义列来打印表格

-o=custom-columns-file=<filename>

使用 <filename> 文件中的自定义列模板打印表格

-o=json

输出 JSON 格式的 API 对象

-o=jsonpath=<template>

打印 jsonpath 表达式中定义的字段

-o=jsonpath-file=<filename>

打印在 <filename> 文件中定义的 jsonpath 表达式所指定的字段。

-o=name

仅打印资源名称而不打印其他内容

-o=wide

以纯文本格式输出额外信息,对于 Pod 来说输出中包含了节点名称

-o=yaml

输出 YAML 格式的 API 对象

二、使用 -o=custom-columns 的示例:

### --- 使用 -o=custom-columns 的示例:
~~~     # 集群中运行着的所有镜像

[root@k8s-master01 ~]#  kubectl get pods -A -o=custom-columns='DATA:spec.containers[*].image'
~~~     # 除 "k8s.gcr.io/coredns:1.6.2" 之外的所有镜像
 
[root@k8s-master01 ~]#  kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="k8s.gcr.io/coredns:1.6.2")].image'
~~~     # 输出 metadata 下面的所有字段,无论 Pod 名字为何

[root@k8s-master01 ~]#  kubectl get pods -A -o=custom-columns='DATA:metadata.*'

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on 2022-03-29 13:12  yanqi_vip  阅读(21)  评论(0)    收藏  举报

导航