<p>I have created a very basic deployment for Kubernetes, but when I try to deploy it</p>

<pre><code>$&gt; kubectl apply -f ./hello-world.yaml
The Deployment "my-deployment" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"bbbb"}: `selector` does not match template `labels`
</code></pre>

<p>With the following yaml file:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  labels:
    app: aaaa
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-deployment
  template:
    metadata:
      labels:
        app: bbbb
    spec:
      containers:
      - name: my-deploy
        image: hello-world
        ports:
        - containerPort: 80
</code></pre>

<p>I have played with the labels and matchLabels a bit, but couldn't fix it. Any suggestions what might be the issue? </p>

<p>Basically, the selector match label in your deployment spec needs to match a label in your template. In your case, you have <code>app: my-deployment</code> as a matching label for the selector and you have <code>app: bbbb</code> in your template, so no match.</p>

<p>You would have to have something either one <code>app: my-deployment</code> or <code>app: bbbb</code> on both so that there is a match.</p>
