<p>I'm trying to wrap my head around the difference between annotations and labels.</p>
<p>My understanding of annotations is that it is metadata that adds key-value pairs that cannot be used by Kubernetes for identifying/filtering the resource.</p>
<p>Labels on the other hand are metadata key-value pairs that can be used by Kubernetes to identify/filter the resource.</p>
<p>Is this right? If this is so, then what is the practical use of annotations? Is it something to do with performance? Where labels are under the scanner of Kubernetes for filters and annotations are purely for adding metadata that is just informational?</p>
<p>But I've seen in cases where deployments needing Nginx or ingress capabilities using annotations. Then how does this get searched or used. Why are labels not used here instead?</p>
<p>When do we use annotations over labels and vice-versa? What are the pros and cons of each?</p>
<p>My understanding is rather limited here, however reading the official docs has not really helped me understand the use case of when do I use annotations vs labels.</p>

<blockquote>
<p>Labels are key/value pairs that can be attached to Kubernetes objects
such as Pods and ReplicaSets. They can be arbitrary, and are useful
for attaching identifying information to Kubernetes objects. Labels
provide the foundation for grouping objects.</p>
<p>Annotations, on the other hand, provide a storage mechanism that
resembles labels: annotations are key/value pairs designed to hold
nonidentifying information that can be leveraged by tools and
libraries.</p>
<p>--   Kubernetes up &amp; running, Chapter 6</p>
</blockquote>
<p><strong>Labels are used to identify resources</strong></p>
<p>Examples of what labels can do:</p>
<ul>
<li><p>find all pods that have a value associated with the key</p>
<p><code>kubectl get pods -l key=val,key2=val2</code></p>
</li>
<li><p>merge and stream logs of the various pod that share the same label</p>
<p><code>kubectl logs -l key=val</code></p>
</li>
</ul>
<p>The reason why labels are used as selectors as opposed to annotations is because most Kubernetes implementation index labels in etcd.</p>
<p><strong>Annotations are used to store data about the resource itself</strong></p>
<p>This usually consists of machine-generated data, and can even be stored in JSON form.</p>
<p>Examples:</p>
<ul>
<li>last updated</li>
<li>managed by</li>
<li>sidecar injection configuration etc</li>
</ul>
