如何获得“就绪"的豆荚列表? [英] How to get list of pods which are "ready"?

查看:63
本文介绍了如何获得“就绪"的豆荚列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用kubectl来检索豆荚列表:

I am using kubectl in order to retrieve a list of pods:

 kubectl get pods --selector=artifact=boot-example -n my-sandbox  

我得到的结果是:

NAME                           READY   STATUS    RESTARTS   AGE
boot-example-757c4c6d9c-kk7mg   0/1     Running   0          77m
boot-example-7dd6cd8d49-d46xs   1/1     Running   0          84m
boot-example-7dd6cd8d49-sktf8   1/1     Running   0          88m

我只想获得"就绪"(已通过readinessProbe)的豆荚.是否有任何kubectl命令仅返回"就绪"窗格?如果不是kubectl命令,那么也许还有其他方法吗?

I would like to get only those pods which are "ready" (passed readinessProbe). Is there any kubectl command which returns only "ready" pods? If not kubectl command, then maybe some other way?

推荐答案

您可以使用以下命令:

kubectl -n your-namespace get pods -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,READY-true:status.containerStatuses[*].ready | grep true

这将为您返回装有"就绪"容器的吊舱.

This will return you the pods with containers that are "ready".

要在没有grep的情况下执行此操作,可以使用以下命令:

To do this without grep, you can use the following commands:

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

kubectl -n your-namespace get pods -o jsonpath='{range .items[*]}{.status.containerStatuses[*].ready.true}{.metadata.name}{ "\n"}{end}'

这将返回"就绪"

这篇关于如何获得“就绪"的豆荚列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆