<p>In a kubernetes <strong>deployment</strong> I specify a port like so:</p>

<pre><code> containers:
 - name: nginx
   image: nginx:latest
   ports:
    - name: nginx-port
      containerPort: 80
      protocol: TCP
</code></pre>

<p>Now in a <strong>service</strong> I can reference that port like so (allows me to only specify the external port in the service):</p>

<pre><code>spec:
  type: ClusterIP
  ports:
  - name: nginx-port
    port: 80
    targetPort: nginx-port
    protocol: TCP
</code></pre>

<p>Now the question, can I reference service and port elsewhere using the following syntax <code>nginx-service.default.svc.cluster.local:nginx-port</code>? You know I can make reference to services using this special names, but I find myself hardcoding the port number like so <code>nginx-service.default.svc.cluster.local:80</code>.</p>

<p>Usually, you refer to a target port by its number. But you can give a specific name to each pod`s port and refer to this name in your service specification.</p>
<p>This will make your service clearer. Here a small example:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: named-port-pod
  labels:
    app: named-port-pod
spec:
  containers:
    - name: echoserver
      image: gcr.io/google_containers/echoserver:1.4
      ports:
      - name: pod-custom-port
        containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: named-port-svc
spec:
  ports:
    - port: 80
      targetPort: pod-custom-port
  selector:
    app: named-port-pod
</code></pre>
