1. 程式人生 > 其它 >|NO.Z.00021|——————————|^^ 標準 ^^|——|KuberNetes&標準.V20|---------------------------------------------------------|常用操作.V06|格式化輸出|

|NO.Z.00021|——————————|^^ 標準 ^^|——|KuberNetes&標準.V20|---------------------------------------------------------|常用操作.V06|格式化輸出|



[CloudNative:KuberNetes&書籤.V20]                                                                      [Applications.KuberNetes] [|DevOps|kubernetes|k8s.二進位制1.20|網路規劃|常用操作|]








一、格式化輸出:以特定格式將詳細資訊輸出到終端視窗可以將-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.*'









===============================END===============================


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



來自為知筆記(Wiz)