Search code examples
dockerkubernetesgoogle-cloud-platformgoogle-kubernetes-enginegoogle-container-registry

How to get image name in Google Cloud Platform Kubernetes Pod


How do you get the digest of a container image running on a pod in ?

Based on the screen-shot below, I would like to be able to retrieve d976aea36eb5 from the pod (logs, YAML etc. whatever is the way to get it)

What I can get from YAML://Deployment/spec/template/spec/containers/image is mysolution.host which is the common name of the image.

enter image description here


Solution

  • If this isn't possible via the kubernetes API, you can do it through the docker registry API.

    What you're looking for is the image's digest, which is the sha256 hash of its manifest. The "Name" column in the screenshot of GCR's UI is the truncated digest of the image.

    The string us.gcr.io/my-project-37111/mysolution.host represents a repository, which is just a collection of images. These images can be referenced by their digest or by a tag.

    You can list all the tags in your repository using gcloud:

    $ gcloud container images list-tags us.gcr.io/my-project-37111/mysolution.host
    

    That will show you the truncated digest as well. For the full digest, you can use the --format=json flag:

    $ gcloud container images list-tags --format=json us.gcr.io/my-project-37111/mysolution.host
    

    If you happen to know the tag (0.0.5-linux for the highlighted image), you can call the registry API directly:

    $ curl \
      -H "Accept: *" \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -I https://us.gcr.io/v2/my-project-37111/mysolution.host/manifests/0.0.5-linux |
      grep "digest"