<p>I'm trying to migrate from docker-compose to kubernetes. I had some issues with volume, so what I did is:</p>
<pre><code>kompose convert --volumes hostPath
</code></pre>
<p>Then I had another issue</p>
<pre><code>no matches for kind &quot;Deployment&quot; in version &quot;extensions/v1beta1&quot;
</code></pre>
<p>So I've changed ApiVersion from extensions/v1beta1 to app/v1 and added &quot;selector&quot;. Now I can't manage with that issue:</p>
<pre><code>
Error from server (Invalid): error when creating &quot;database-deployment.yaml&quot;: Deployment.apps &quot;database&quot; is invalid: spec.template.metadata.labels: Invalid value: map[string]string{&quot;io.kompose.service&quot;:&quot;database&quot;}: `selector` does not match template `labels`
Error from server (Invalid): error when creating &quot;phpmyadmin-deployment.yaml&quot;: Deployment.apps &quot;phpmyadmin&quot; is invalid: spec.template.metadata.labels: Invalid value: map[string]string{&quot;io.kompose.service&quot;:&quot;phpmyadmin&quot;}: `selector` does not match template `labels`
Error from server (Invalid): error when creating &quot;webserver-deployment.yaml&quot;: Deployment.apps &quot;webserver&quot; is invalid: spec.template.metadata.labels: Invalid value: map[string]string{&quot;io.kompose.service&quot;:&quot;webserver&quot;}: `selector` does not match template `labels`

</code></pre>
<p>database-deployment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert --volumes hostPath
    kompose.version: 1.19.0 (f63a961c)
  creationTimestamp: null
  labels:
    io.kompose.service: database
    app: database
  name: database
spec:
  selector:
    matchLabels:
      app: database
  template:
    metadata:
      labels:
        io.kompose.service: database
  replicas: 1
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert --volumes hostPath
        kompose.version: 1.19.0 (f63a961c)
      creationTimestamp: null
      labels:
        io.kompose.service: database
    spec:
      containers:
      - env:
        - name: MYSQL_DATABASE
          value: Bazadanerro
        - name: MYSQL_PASSWORD
          value: P@$$w0rd
        - name: MYSQL_ROOT_PASSWORD
          value: P@$$w0rd
        - name: MYSQL_USER
          value: dockerro
        image: mariadb
        name: mysql
        resources: {}
      restartPolicy: Always
status: {}
</code></pre>
<p>phpmyadmin-deployment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert --volumes hostPath
    kompose.version: 1.19.0 (f63a961c)
  creationTimestamp: null
  labels:
    io.kompose.service: phpmyadmin
    app: phpmyadmin
  name: phpmyadmin
spec:
  selector:
    matchLabels:
      app: phpmyadmin
  template:
    metadata:
      labels:
        io.kompose.service: database
  replicas: 1
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert --volumes hostPath
        kompose.version: 1.19.0 (f63a961c)
      creationTimestamp: null
      labels:
        io.kompose.service: phpmyadmin
    spec:
      containers:
      - env:
        - name: MYSQL_PASSWORD
          value: P@$$w0rd
        - name: MYSQL_ROOT_PASSWORD
          value: P@$$w0rd
        - name: MYSQL_USER
          value: dockerro
        - name: PMA_HOST
          value: database
        - name: PMA_PORT
          value: &quot;3306&quot;
        image: phpmyadmin/phpmyadmin
        name: phpmyadmins
        ports:
        - containerPort: 80
        resources: {}
      restartPolicy: Always
status: {}
</code></pre>
<p>And webserver-deployment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert --volumes hostPath
    kompose.version: 1.19.0 (f63a961c)
  creationTimestamp: null
  labels:
    io.kompose.service: webserver
    app: webserverro
  name: webserver
spec:
  selector:
    matchLabels: 
      app: webserverro
  template:
    metadata:
      labels:
        io.kompose.service: webserver
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert --volumes hostPath
        kompose.version: 1.19.0 (f63a961c)
      creationTimestamp: null
      labels:
        io.kompose.service: webserver
    spec:
      containers:
      - image: webserver
        name: webserverro
        ports:
        - containerPort: 80
        resources: {}
        volumeMounts:
        - mountPath: /var/www/html
          name: webserver-hostpath0
      restartPolicy: Always
      volumes:
      - hostPath:
          path: /root/webserverro/root/webserverro
        name: webserver-hostpath0
status: {}
</code></pre>
<p>What am I doing wrong?</p>

Incybro Shostak
<p>The error is self-explanatory: <code>&quot;selector&quot; does not match template &quot;labels&quot;</code>.</p>
<p>Edit your YAML files and set the same key-value pairs in both <code>selector.matchLabels</code> and <code>metadata.labels</code>.</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  selector:
    matchLabels: # &lt;---- This
      app: database
  template:
    metadata:
      labels: # &lt;---- This
        io.kompose.service: database 
</code></pre>
<ul>
<li>Why <code>selector</code> field is important?</li>
</ul>
<blockquote>
<p>The <code>selector</code> field defines how the Deployment finds which Pods to manage. In this case, you simply select a label that is defined in the Pod template (app: nginx). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.</p>
</blockquote>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment" rel="nofollow noreferrer"> Reference </a></li>
</ul>
<p><strong>Update:</strong></p>
<p>One possible sample can be:</p>
<pre><code>spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: database
  template:
    metadata:
      labels:
         app.kubernetes.io/name: database
</code></pre>
<ul>
<li>Visit <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/" rel="nofollow noreferrer">recommended labels</a></li>
</ul>
<p><strong>Update2:</strong></p>
<blockquote>
<p>no matches for kind &quot;Deployment&quot; in version &quot;extensions/v1beta1&quot;</p>
</blockquote>
<p>The <code>apiVersion</code> for <code>Deployment</code> object is now <strong>apps/v1</strong>.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1 # &lt;-- update here.
kind: Deployment
... ... ...
</code></pre>
