简体   繁体   English

在给定容器ID的情况下如何查找吊舱名称

[英]How to find the pod name given a container ID

Is there a way to find the pod name for a given Docker container ID? 有没有一种方法可以找到给定Docker容器ID的容器名称?

I can do it the other way round "kubectl describe pods" but then I have to run it on all the pods. 我可以用另一种方式围绕“ kubectl描述豆荚”来做,但是然后我必须在所有豆荚上运行它。

Yes, you can get the pod name given a container ID using the following kubectl request: 是的,您可以使用以下kubectl请求获得给定容器ID的容器名称:

kubectl get pod -o jsonpath='{range .items[?(@.status.containerStatuses[].containerID=="docker://<container_id>")]}{.metadata.name}{end}' -n <namespace>

where <container_id> is the long docker container ID and <namespace> is namespace which we can skip if our pod is in default namespace. 其中<container_id>是长的docker容器ID,而<namespace>是命名空间,如果我们的pod在默认命名空间中,则可以跳过。

For example: 例如:

kubectl get pod -o jsonpath='{range .items[?(@.status.containerStatuses[].containerID=="docker://686bc30be6e870023dcf611f7a7808516e041c892a236e565ba2bd3e0569ff7a")]}{.metadata.name}{end}'
nginx-deployment-569477d6d8-xtf42 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据容器名称或容器ID查找容器图像路径 - How to find the container image path based on pod name or container ID 如何在 kubernetes pod 的容器中设置用户名? - How to set user name in container of kubernetes pod? 如何检索运行给定进程的 pod/容器 - How to retrieve the pod/container in which run a given process 鉴于此 while 循环,如何查看 pod 中容器中发生的情况? - how to look what happend in the container in pod given this while loop? 如何在 K8s 中获取给定 pod-name 和命名空间名称的 pod 的日志记录级别? - How to get logging level of a pod given pod-name and namespace name in K8s? 如何查看 Pod 日志:必须为 pod 指定容器名称……选择以下之一:[wait main] - How to see Pod logs: a container name must be specified for pod… choose one of: [wait main] 如何通过oc编辑部署在容器中插入ca-cert <pod/container_name> - How to insert a ca-cert inside a container through oc edit deploy <pod/container_name> 我们如何在kubernetes部署yamls中获得诸如pod id或container id之类的独特信息 - How do we get something unique like pod id or container id in kubernetes deployment yamls kubectl执行失败,出现“容器” <command> 不适用于广告连播 <pod_name> ” - kubectl exec failed with “container <command> is not valid for pod <pod_name>” 以编程方式获取Kubernetes中容器所属的pod的名称? - Programmatically get the name of the pod that a container belongs to in Kubernetes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM