Get the image and SHA image ID of images in pod on Kubernetes deployment

8/10/2017

How can I get the image ID (the docker sha256 hash) of a image / container within a Kubernetes deployment?

-- Chris Stryczynski
kubectl
kubernetes

2 Answers

2/3/2020

An example without jq usage.

Using jsonpath:

kubectl get pods $YOUR_POD_NAME -o jsonpath="{..imageID}"

Using go-templates

kubectl get pods $YOUR_POD_NAME -o go-template --template="{{ range .status.containerStatuses }}{{ .imageID }}{{end}}"

Reference: https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-containers-filtering-by-pod-namespace

-- Andrew
Source: StackOverflow

8/10/2017

Something like this will do the trick (you must have jq installed):

$ kubectl get pod --namespace=xx yyyy -o json | jq '.status.containerStatuses[] | { "image": .image, "imageID": .imageID }'
{
  "image": "nginx:latest",
  "imageID": "docker://sha256:b8efb18f159bd948486f18bd8940b56fd2298b438229f5bd2bcf4cedcf037448"
}
{
  "image": "eu.gcr.io/zzzzzzz/php-fpm-5:latest",
  "imageID": "docker://sha256:6ba3fe274b6110d7310f164eaaaaaaaaaa707a69df7324a1a0817fe3b475566a"
}
-- Janos Lenart
Source: StackOverflow