Kubectl command to list pods of a deployment in Kubernetes

好久不见. 提交于 2020-12-01 08:59:27

问题


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

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.

I also tried kc get -o wide deployments hellodeployment, but it does not print the Pod names.


回答1:


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

or

$ kubectl get pods --selector=app=http-svc


来源:https://stackoverflow.com/questions/52957227/kubectl-command-to-list-pods-of-a-deployment-in-kubernetes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!