Differences between Kubernetes Annotations and Labels

Objects in Kubernetes can have metadata in two primary forms: annotations and labels.

It’s easy to confuse when to use which because they’re both key-value objects.

The main difference between annotations and labels is that annotations aren’t meant to be used to select objects, and labels are.

Another difference is the format of a valid annotation can take the form of a domain name, such as cluster-autoscaler.kubernetes.io/safe-to-evict.

If you ever want to use selectors to select a group of pods, you would be selecting the pods by labels and never annotations.

Here’s a quick snippet from the Kubernetes documentation:

You can use either labels or annotations to attach metadata to Kubernetes objects. Labels can be used to select objects and to find collections of objects that satisfy certain conditions. In contrast, annotations are not used to identify and select objects. The metadata in an annotation can be small or large, structured or unstructured, and can include characters not permitted by labels. It is possible to use labels as well as annotations in the metadata of the same object.


Like what you've read?

If you're an engineering leader or developer, you should subscribe to my 80/20 DevOps Newsletter. Give me 1 minute of your day, and I'll teach you essential DevOps skills. I cover topics like Kubernetes, AWS, Infrastructure as Code, and more.

Not sure yet? Check out the archive.

Unsubscribe at any time.