用于列出 Kubernetes 中部署的 pod 的 Kubectl 命令 [英] Kubectl command to list pods of a deployment in Kubernetes

查看:41
本文介绍了用于列出 Kubernetes 中部署的 pod 的 Kubectl 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 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 获取 pods|grep 你好

但是当我只想知道给定部署的 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.

推荐答案

有一个 label 用于 selector 在部署中.这就是 deployment 管理其 pod 的方式.例如,对于标签或选择器 app=http-svc,您可以执行类似的操作并避免使用 grep 并列出所有 pod(这会随着您的数量而变得有用)豆荚变得非常大):

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

这篇关于用于列出 Kubernetes 中部署的 pod 的 Kubectl 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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