【问题标题】:How to use custom column that include ready如何使用包含准备好的自定义列
【发布时间】:2022-01-01 13:51:07
【问题描述】:

您好,我正在尝试运行 kubectl -n*** get pods

这会返回标准的,它包括名称、就绪和状态...

我需要的是名字并准备好 但是,我无法通过使用自定义列来做到这一点。 需要有关如何将就绪列添加回自定义列的帮助

kubectl -n*** 获取 pod -o=custom-columns="NAME:.metadata.name"

提前致谢

【问题讨论】:

  • “READY”列的值不是取自 pod 本身,而是动态计算的,您不能为此使用 custom-columns 的 json-path 表达式。跨度>

标签: linux kubernetes kubectl


【解决方案1】:
kubectl get pods -o custom-columns='NAME:metadata.name,READY:status.conditions[?(@.type=="Ready")].status'

【讨论】:

    【解决方案2】:

    使用go-template的解决方案:

     kubectl  get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready }}{{$element.metadata.name}}  {{"READY\n"}}{{end}}{{end}}{{end}}'
    

    例子:

    k get pod
    NAME                     READY   STATUS    RESTARTS        AGE
    httpd-757fb56c8d-2vnw4   1/1     Running   2 (6h24m ago)   3d3h
    readiness-exec            0/1     Running   0               22s #<---this is not ready
    nginx                    1/1     Running   2 (6h24m ago)   4d1h
    nginx-6799fc88d8-5cflk   1/1     Running   2 (6h24m ago)   3d3h
    

    // non-ready(readiness-exec) pod 未列出:

    kubectl  get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready }}{{$element.metadata.name}}  {{"READY\n"}}{{end}}{{end}}{{end}}'
    httpd-757fb56c8d-2vnw4  READY
    nginx  READY
    nginx-6799fc88d8-5cflk  READY
    

    //一旦readiness-exec pod 准备就绪:

    kubectl  get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready }}{{$element.metadata.name}}  {{"READY\n"}}{{end}}{{end}}{{end}}' |column -t
    httpd-757fb56c8d-2vnw4   READY
    readiness-exec           READY
    nginx                    READY
    nginx-6799fc88d8-5cflk   READY
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 2012-05-21
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 2015-03-14
      • 2019-12-30
      • 2012-03-26
      相关资源
      最近更新 更多