<p>I have a question about labels and names, in this example manifest file</p>
<p>apiVersion: apps/v</p>
<pre><code>1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
</code></pre>
<p>I can see that the <strong>name of the deployment</strong> is &quot;nginx-deployment&quot; and the <strong>pod name</strong> is &quot;nginx&quot;? or is it the running container?
Then I see in the console that the pods would have a hash attached to the end of its name, I believe this is the revision number?
I just want to decipher the <strong>names</strong> from the <strong>labels</strong> from the <strong>matchLables</strong>, so for example I can use this service manifest to expose the pods with a certain label:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 60000
    targetPort: 80
</code></pre>
<p>will this service expose all pods with the <strong>selector</strong> : app:nginx ?</p>
<p>thanks</p>

Tlink
<p>The Deployment has your specifed name &quot;nginx-deployment&quot;.</p>
<p>However you did not define a Pod with a fixed name, you define a template for the pods managed by this deployment.</p>
<p>The Deployment manages 3 pods (because of your replicas 3), so it will use the template to build this three pods.</p>
<p>There will also be a Replica Set with a hash and this will manage the Pods, but this is better seen by following the example below.</p>
<p>Since a deployment can manage multiple pods (like your example with 3 replicas) or needing one new Pod when updating them, a deployment will not exactly use the name specified in the template, but will always append a hash value to keep them unique.</p>
<p>But now you would have the problem to have all Pods loadbalanced behind one Kubernetes Service, because they have different names.</p>
<p>This is why you denfine a label &quot;app:nignx&quot; in your template so all 3 Pods will have this label regardless of there name and other labels set by Kubernetes.</p>
<p>The Service uses the selector to find the correct Pods. In your case it will search them by label &quot;app:nginx&quot;.</p>
<p>So yes the Service will expose all 3 Pods of your deployment and will loadbalance trafic between them.</p>
<p>You can use <code>--show-labels</code> for <code>kubectl get pods</code> to see the name and the assigned labels.</p>
<p>For a more complete example see:
<a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/deployment/</a></p>
