Kubectl命令在Kubernetes中列出部署的Pod [英] Kubectl command to list pods of a deployment in Kubernetes
问题描述
是否可以使用kubectl
仅列出属于部署的Pod?
目前,我这样做是为了获得豆荚:
Is there a way to use kubectl
to list only the pods belonging to a deployment?
Currently, I do this to get pods:
kubectl get pods| grep hello
但是,当我有兴趣仅了解给定部署的Pod时,获得所有Pod似乎是过大的选择.我使用此命令的输出来查看所有Pod的状态,然后可能执行其中的一个.
But it seems an overkill to get ALL the pods when I am interested to know only the pods for a given deployment. I use the output of this command to see the status of all pods, and then possibly exec into one of them.
我也尝试过kc get -o wide deployments hellodeployment
,但是它不显示Pod名称.
I also tried kc get -o wide deployments hellodeployment
, but it does not print the Pod names.
推荐答案
有一个选择器的窗格中的noreferrer>标签. a>在部署中.这就是部署对其吊舱进行管理的方式.例如,对于标签或选择器app=http-svc
,您可以执行类似的操作,并避免使用grep
并列出所有吊舱(当吊舱数量变得非常大时,此功能将非常有用):
There's a label in the pod for the selector in the deployment. That's how a deployment manages its pods. For example for the label or selector app=http-svc
you can do something like that this and avoid using grep
and listing all the pods (this becomes useful as your number of pods becomes very large):
$ kubectl get pods -l=app=http-svc
或
$ kubectl get pods --selector=app=http-svc
这篇关于Kubectl命令在Kubernetes中列出部署的Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!