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

Viewed 21055

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

4 Answers

Right way to do this:

kubectl get pods --all-namespaces -o jsonpath="{.items[*].status.containerStatuses[*].imageID}" | tr -s '[[:space:]]' '\n' | sort | uniq -c

The simplest one to use is:

For getting images SHA value of all the pods in a single namespace:

  • kubectl get pods -n <your-namespace> -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'

For getting images SHA value of all the pods in all the namespace:

  • kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'
Related