<p>In the book <a href="https://www.goodreads.com/book/show/26759355-kubernetes" rel="nofollow noreferrer">Kubernetes: Up &amp; Running</a>, on the section "Creating Deployments", it has a yaml file that starts like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels: 
    run: nginx
</code></pre>

<p>What is the use of applying a label to a deployment? I understand how the pods and a service interact, but when do the labels in a deployment spring into action?</p>

<p>Labels are useful to group inter-related apps. For example, you have a application that require a Deployment, a Service, a Database(maybe deployed with deployment or statefulset). Now,if you use similar labels to all these resources(let it is <code>app: my-app</code>), then you can list,delete etc. operation based on this label.</p>

<p>For example, if you want to list all resources for your particular application, then you can use <code>kubectl get all -l app=my-app</code>.</p>

<p>For more details, please read this <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="nofollow noreferrer">article</a>.</p>
