<p>The first and most minimal <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="noreferrer">example of a Deployment in the Kubernetes documentation</a> has the <code>app: nginx</code> line that repeats itself three times. I understand it's a tag, but I haven't found anything that explains why this needs to be specified for all of:</p>

<ol>
<li><code>metadata.labels</code>,</li>
<li><code>spec.selector.matchLabels</code>, and</li>
<li><code>spec.template.metadata.labels</code></li>
</ol>

<p>The example deployment file:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
</code></pre>

<p>So 1 and 3 are technically unrelated. 1 is the labels for the deployment object and only matter for your own organizational purposes. 3 are the labels that will be put on the generated pods. As for why Deployments rely on manually specifying a selector against the pod labels, it is to ensure stay stateless. The deployment controller can restart at any time and things will be safe. It could be improved in the future though, if someone has a solid proposal that takes care of all the edge cases.</p>
