Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get docker-image labels from kubernetes API

Tags:

kubernetes

We are building our docker-images, and adding a few metadata-labels during docker build, e.g:

docker build --label no.company.version=1.2.3 .

When we at some point later in time use this image in a kubernetes pod, we would like to retreive that labels from the kubernetes api. This would be useful for tracking other metadata than what is encoded in the image tag itself.

The labels are available through docker on the node, but I can not find any way to retreive them in kubernetes. Is this possible?

like image 620
Nils Otto Avatar asked Aug 09 '17 19:08

Nils Otto


People also ask

How do I get a Docker image label?

To check the labels of a particular Image, you can use the Docker Inspect command. Start the Docker Container. Execute the Inspect Command. Inside the LABELS object, you can find all the labels associated with the image that you have specified inside your Dockerfile.


2 Answers

If using Openshift, the docker labels are visible on the ImageStreamTag object (apiVersion: image.openshift.io/v1) if you happen to be using that feature.

oc get istag myimage:latest -o yaml

apiVersion: image.openshift.io.v1
generation: 2
image:
    dockerImageLayers:
    - mediaType: application/vnd.docker.image.rootfs.diff.tar.gzip
      name: sha256:690b26398d8aadd19a2936c1b51a335c06e0887775135f3186bc318c2dbf6d15
      size: 31494540
    - ...etc...
  dockerImageManifestMediaType: application/vnd.docker.distribution.manifest.v2+json
  dockerImageMetadata:
    Architecture: amd64
    Config:
      Image: sha256:5593b121415d0e9e23ae1041628869379937580fd29d4e90d163f2101bd4d96d
      Labels:
        architecture: x86_64
        mvn.version: 1.0.0-SNAPSHOT
        git.branch: master
        git.revision: 17c5424fcf578b13144e03d638becfb86e18ff92
... etc...
like image 192
Ed Randall Avatar answered Sep 19 '22 17:09

Ed Randall


querying docker metadata from kubernetes api is not supported for now. there is a PR opened to accommodate this request. please follow
https://github.com/kubernetes/kubernetes/issues/47368

like image 25
P Ekambaram Avatar answered Sep 20 '22 17:09

P Ekambaram