<p>I understand that services use a selector to identify which pods to route traffic to by thier labels.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: svc
spec:
  ports:
  - name: tcp
    protocol: TCP
    port: 443
    targetPort: 443
  selector:
    app: nginx
</code></pre>
<p>Thats all well and good.</p>
<p>Now what is the difference between this selector and the one of the <code>spec.selector</code> from the deployment. I understand that it is used so that the deployment can match and manage its pods.</p>
<p>I dont understand however why i need the extra <code>matchLabels</code> declaration and cant just do it like in the service. Whats the use of this semantically?</p>
<pre><code>apiVersion: apps/v1 
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1 
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
</code></pre>
<p>Thanks in advance</p>

<p>In the <code>Service</code>'s <code>spec.selector</code>, you can identify which pods to route traffic to only by their labels.</p>
<p>On the other hand, in the <code>Deployment</code>'s <code>spec.selector</code> you have two options to decide on which node the pods will be scheduled on, which are: <code>matchExpressions</code>, <code>matchLabels</code>.</p>
