Kubernetes: label vs annotation

1 min read | by Jordi Prats

On Kubernetes there are two main ways of attaching metedata to objects un Kubernetes: Labels and Annotation.

What's the difference? When should I choose one over the other?

We can take a look at the Kubernetes documentation:

Annotations

The definition of Annotations is quite generic: They are intented to be able to attach arbitrary non-identifying metadata to objects.

Labels

Labels are intended to:

  • Specify identifying attributes of objects that are meaningful and relevant to user.
  • To organize and to select subsets of objects

But the key is the following:

Non-identifying information should be recorded using annotations

Label vs Annotation

In a nutshell:

  • When you are not trying to identify a group of pods it should be an annotation.
  • If the data is intended to be used by an human, then it should be an annotation.
  • Otherwise, it's should be a label

Posted on 01/03/2022