<p>Deploying my service to production:</p>

<pre><code>envsubst &lt; ./kubernetes/pre-production/aks.yaml | kubectl apply -f -
</code></pre>

<p>I'm getting the following error:</p>

<blockquote>
  <p>The Deployment "moverick-mule-pre" is invalid:
  spec.template.metadata.labels: Invalid value:
  map[string]string{"commit":"750a26deebc3582bec4bfbb2426b3f22ee042eaa",
  "app":"moverick-mule-pre"}: <code>selector</code> does not match template
  <code>labels</code></p>
</blockquote>

<p>My yaml file is:</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: moverick-mule-pre
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: moverick-mule-pre
        commit: $CI_COMMIT_SHA
    spec:
      containers:
      - name: moverick-mule-pre
        image: $REGISTRY_SERVER_PRE/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
        imagePullPolicy: Always
        ports:
        - containerPort: 80
        envFrom:
          - secretRef:
              name: moverick-pre
        livenessProbe:
          httpGet:
            path: /console
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
        volumeMounts:
        - name: logs
          mountPath: /opt/mule/logs/
        - name: asc
          mountPath: /opt/mule/asc/
      imagePullSecrets:
      - name: registry-pre
      volumes:
      - name: logs
        azureFile:
          secretName: azure-files-pre
          shareName: logs-pre
          readOnly: false
      - name: asc
        azureFile:
          secretName: azure-asc-pre
          shareName: asc-pre
          readOnly: false
---
apiVersion: v1
kind: Service
metadata:
  name: moverick-mule-pre
spec:
  ports:
  - port: 80
  selector:
    app: moverick-mule-pre
</code></pre>

<p>You need to add <code>selector</code> in <code>spec</code> of Deployment.</p>
<p>And also, these <code>selector</code> should match with <code>labels</code> in PodTemplate.</p>
<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: moverick-mule-pre
spec:
  replicas: 2
  selector:
    matchLabels:
      app: moverick-mule-pre
      commit: $CI_COMMIT_SHA
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: moverick-mule-pre
        commit: $CI_COMMIT_SHA
</code></pre>
<p>Otherwise, you will get error like below</p>
<blockquote>
<p>The Deployment &quot;moverick-mule-pre&quot; is invalid:</p>
<ul>
<li>spec.selector: Required value</li>
<li>spec.template.metadata.labels: Invalid value: map[string]string{...} <code>selector</code> does not match template <code>labels</code></li>
</ul>
</blockquote>
