title: kubernetes: Role of selector in service vs deployment
body: <p>From the <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">official example</a> of <code>Kubernetes</code> documentation site on deploying a <code>Wordpress</code> application with mysql:</p>
  
  <p>The service definition of <code>mysql</code>:</p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: wordpress-mysql
    labels:
      app: wordpress
  spec:
    ports:
      - port: 3306
    selector:
      app: wordpress
      tier: mysql
    clusterIP: None
  </code></pre>
  
  <p>The deployment definition of <code>mysql</code></p>
  
  <pre><code>apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
  kind: Deployment
  metadata:
    name: wordpress-mysql
    labels:
      app: wordpress
  spec:
    selector:
      matchLabels:
        app: wordpress
        tier: mysql
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app: wordpress
          tier: mysql
  </code></pre>
  
  <p>My question is the following:</p>
  
  <p>The <code>Deployment</code> definition, has a <code>matchLabel</code> <code>selector</code>, so that it will <strong>match</strong> the pod defined below that has the <code>app: wordpress</code> <strong>and</strong> <code>tier:mysql</code> labels.</p>
  
  <p>Why the <code>Service</code> <code>selector</code> does not require a <code>matchLabel</code> directive for the same purpose? What is the "selection" of service performed upon?</p>