oui*_*oui 3 go-templates kubernetes kubectl
我想自定义输出:
kubectl get pod . . .
Run Code Online (Sandbox Code Playgroud)
用--output=go-template
代替--output=yaml
或--output=json
。
get
我的目的是使用一个命令获取除了默认列(例如,NAME、READY、STATUS 等..,.)之外的其他值(例如,容器端口) :
kubectl get pods --output=go-template --template=$GO_TEMPLATE
#=>
NAME READY STATUS RESTARTS AGE CONTAINER PORTS . . .
. . . . . . . . . . . . . . . . . . . . .
client-qfr4s 1/1 Running 0 14d 80,443 . . .
. . . . . . . . . . . . . . . . . . . . .
Run Code Online (Sandbox Code Playgroud)
什么是$GO_TEMPLATE
?
get
您可以使用以下标志将自定义列添加到命令的输出--output=custom-columns
:
kubectl get pods \
--output=custom-columns='NAME:.metadata.name,STATUS:.status.phase,RESTARTS:.status.containerStatuses[].restartCount,CONATAINER_NAME:.spec.containers[*].name,PORT:.spec.containers[*].ports[*],READY:.status.containerStatuses[*].ready'
#=>
NAME STATUS RESTARTS CONATAINER_NAME PORT READY
nginx-6bc98f4797-7kv6m Pending 0 busy,nginx map[containerPort:8000 protocol:TCP] false,true
nginx-6bc98f4797-zv4sp Pending 0 busy,nginx map[containerPort:8000 protocol:TCP] false,true
php-apache-5986bb6b9-gllq8 Running 5 php-apache map[containerPort:80 protocol:TCP] true
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到更多详细信息
归档时间: |
|
查看次数: |
3343 次 |
最近记录: |