Reputation: 739
Is there a way to find the pod name for a given Docker container ID?
I can do it the other way round "kubectl describe pods" but then I have to run it on all the pods.
Upvotes: 2
Views: 10710
Reputation: 28733
Yes, you can get the pod name given a container ID using the following kubectl
request:
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.
For example:
kubectl get pod -o jsonpath='{range .items[?(@.status.containerStatuses[].containerID=="docker://686bc30be6e870023dcf611f7a7808516e041c892a236e565ba2bd3e0569ff7a")]}{.metadata.name}{end}'
nginx-deployment-569477d6d8-xtf42
Upvotes: 9