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.
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.
https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ – Kubernetes documentation about annotations
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ – Kubernetes documentation about labels
The commands were executed using minishift and the following client/server versions of OpenShift.
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.