<p>When creating a Kubernetes service, I'm trying to understand what fields in the YAML service definition need to match to a PODs definition.</p>
<p>For example, given the service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx-selector
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
</code></pre>
<p>What field in the Pod definition needs to say <code>nginx-selector</code>.  I think it's the field I've labeled (metadata.labels.app = nginx-selector).</p>
<p>So given this Pod definition</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp
  labels:
    app: nginx-selector
spec:
  containers:
    - name: myapp
      image: pats2265/myapp
      labels:
        app: does-this-matter
      ports:
        - containerPort: 8080
</code></pre>
<p>So many examples use names that are identical between several fields so I wanted a trivial example to spell it out.</p>
<p>This was a good diagram:
<a href="https://i.stack.imgur.com/RW6xdl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RW6xdl.png" alt="enter image description here" /></a>
Taken from <a href="https://matthewpalmer.net/kubernetes-app-developer/articles/service-kubernetes-example-tutorial.html" rel="nofollow noreferrer">https://matthewpalmer.net/kubernetes-app-developer/articles/service-kubernetes-example-tutorial.html</a></p>
<p>But it didn't show the corresponding Pod definition.</p>
<p>Searches came up with this question:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/51011689/how-to-communicate-between-pods-in-a-service">How to communicate between pods in a service?</a> - Which I think answers my question, so this can be marked as a duplicate but my question is more specific so I'd like to keep it to help others out.</li>
</ul>

PatS
<p>You are right...its the label of pod which should match with selector defined in service. Check this link for more understanding- <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/</a></p>
