Difference between docker labels and kubernetes labels?

6/9/2020

I am seeing many more labels with the command "docker inspect" than the kubernetes labels shown in "kubectl describe" or "kubectl get pods --show-labels". Is it possible to see all of the same docker labels using a kubectl command, or is this not possible as the docker labels are not related to the pod labels within kubernetes?

-- maxman722
docker
kubernetes
label
podspec

1 Answer

6/9/2020

Both labels consist of key-value pairs only.

In Kubernetes labels are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system. Labels can be used to organize and to select subsets of objects. So for example, if you label a deployment with rules that schedules the pod on a specific node, it is possible using that. Or say for example if a pod can have ingress traffic from one specific service having label XYZ, it is done using labels. There are so many ways you can make use of it.

On the other hand, Docker offers support to add labels into images as a way to add custom metadata. So in Dockerfile you mention it as:

LABEL <key>=<value> <key>=<value> <key>=<value>

It will store data as:

LABEL multi.label1="value1" \
      multi.label2="value2" \
      other="value3"

You can inspect it as:

docker inspect \
       --format "{{ index .Config.Labels \"multi.label2\"}}"
       <your image>

As per docker documentation guidelines are : https://docs.docker.com/config/labels-custom-metadata/

The link http://label-schema.org/rc1/ is useful too about labeling. Build time labels are well defined here:

http://label-schema.org/rc1/#build-time-labels

Accessing docker's label is not feasible I think, as it is not exposed via Kubernetes API.

-- ARINDAM BANERJEE
Source: StackOverflow