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.
Master GitHub Actions with a Senior Infrastructure Engineer
As a senior staff infrastructure engineer, I share exclusive, behind-the-scenes insights that you won't find anywhere else. Get the strategies and techniques I've used to save companies $500k in CI costs and transform teams with GitOps best practices—delivered straight to your inbox.
Not sure yet? Check out the archive.
Unsubscribe at any time.