How can I get the image ID (the docker sha256 hash) of a image / container within a Kubernetes deployment?
How can I get the image ID (the docker sha256 hash) of a image / container within a Kubernetes deployment?
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}}"
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}'