<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>

pkaramol
<p>The <code>Service</code> is a concept that makes your container (in this case hosting wordpress) available on a given port. It maps an external port (the <code>Node's</code> port) to and internal port (the container/pod's port). It does this by using the <code>Pod's</code> networking capabilities. The selector is a way of specifying in the service which <code>Pod</code> the port should be opened on. The <code>Deployment</code> is actually just a way of grouping things together - the <code>Pod</code> itself holds the Wordpress container, and the port that's defined in the service is available through the <code>Pod</code> networking.</p>

<p>This is a simple explanation, there are different kinds of services.</p>
