Bartosz Bierkowski - Low dose cloud

OpenShift Morsels: labels vs annotations

Day #3 – When describing pods and other resources, you can see two sets of key value pairs. One is called Labels and the other Annotations.

Below you can see just a part of oc describe output that lists both labels and annotations.

I get to use labels quite often and I hardly ever use annotations. I asked myself what are they and what is their purpose? From the example above it seems that labels are more concise than annotations. It is because they serve different purposes.

Labels should be used by end users. If something is meant to be used by a person, put it into a label.

Annotations on the other hand are dedicated to be used for technical purposes. You can see in the example above that the Annotation kubernetes.io/created-by contains some JSON. Otherr values are similar to what you can find in the Labels.

Documentation

The official documentation for OpenShift and Kubernetes serve quite a few examples for both. Just search for annotation or label on the pages below to get a better feeling on how they are used.

Annotations

https://docs.openshift.org/3.6/install_config/configuring_routing.html

https://docs.openshift.org/3.6/security/container_content.html#security-annotating-image-objects

https://docs.openshift.org/3.6/dev_guide/secrets.html#service-serving-certificate-secrets

https://docs.openshift.org/3.6/dev_guide/secrets.html#secrets-troubleshooting

https://docs.openshift.org/3.6/admin_guide/managing_networking.html

https://docs.openshift.org/3.6/install_config/upgrading/manual_upgrades.html#updating-policy-definitions

https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ – Kubernetes documentation about annotations

Labels

https://docs.openshift.org/3.6/install_config/persistent_storage/selector_label_binding.html

https://docs.openshift.org/3.6/install_config/storage_examples/binding_pv_by_label.html

https://docs.openshift.org/3.6/dev_guide/cron_jobs.html

https://docs.openshift.org/3.6/dev_guide/projects.html#filtering-by-labels

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ – Kubernetes documentation about labels

Environment

The commands were executed using minishift and the following client/server versions of OpenShift.

Client:
oc v3.6.1+008f2d5
client kubernetes v1.6.1+5115d708d7
Server:
openshift v3.6.0+c4dd4cf
server kubernetes v1.6.1+5115d708d7

Newsletter

Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.

As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.

Did you like the article?
Join the newsletter to receive notifications about new articles.
I respect your privacy.