【问题标题】:How to get the same output with go-template as kubectl get pod output如何使用 go-template 获得与 kubectl get pod output 相同的输出
【发布时间】:2020-05-02 13:56:50
【问题描述】:

我想通过 go-template 获取 kubectl get pod 输出。 我不知道 kubectl get pod -o yaml(json) 不包含 READY 值(例如 1/1)的方式

kubectl get pod
NAME           READY   STATUS    RESTARTS   AGE
client-qfr4s   1/1     Running   0          14d

我的目的是通过一次性 kubectl 命令获取除了默认列(NAME、READN、STATUS 等)之外的其他值(例如容器端口)。

【问题讨论】:

    标签: kubernetes kubectl


    【解决方案1】:

    您可以在 kubectl get 命令中添加自定义列,如下所示

        $ kubectl get pods -o 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
    

    您可以找到更多详情here

    【讨论】:

      【解决方案2】:

      你可以用describe代替get

      kubectl describe pod
      

      您将获得如下完整状态:

      Conditions:
        Type              Status
        Initialized       True
        Ready             True
        ContainersReady   True
        PodScheduled      True
      

      【讨论】:

        猜你喜欢
        • 2019-12-09
        • 1970-01-01
        • 2014-12-28
        • 2021-06-30
        • 1970-01-01
        • 2021-08-05
        • 2019-08-09
        • 1970-01-01
        • 2014-01-11
        相关资源
        最近更新 更多