<p>Hi the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#containerport-v1-core" rel="nofollow noreferrer">documentation </a> says about the name field in containers.ports :</p>
<blockquote>
<p>name  If specified, this must be an IANA_SVC_NAME and unique within the pod. Each named port in a pod must have a unique name. Name for the port that can be referred to by services.</p>
</blockquote>
<p>I tried to use it in my service as follows but I have an error from the parser :</p>
<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: banana-app
  labels:
    app: banana
spec:
  containers:
    - name: banana-app
      image: hashicorp/http-echo
      args:
        - &quot;-text=banana&quot;
      ports:
      - containerPort: 5678
        name: bananaport
  terminationGracePeriodSeconds: 0
---

kind: Service
apiVersion: v1
metadata:
  name: banana-service
spec:
  selector:
    app: banana
  ports:
    - port: bananaport
</code></pre>
<p>The parser error is :</p>
<blockquote>
<p>error: error validating &quot;temp.yml&quot;: error validating data: ValidationError(Service.spec.ports[0].port): invalid type for io.k8s.api.core.v1.ServicePort.port: got &quot;string&quot;, expected &quot;integer&quot;; if you choose to ignore these errors, turn validation off with --validate=false</p>
</blockquote>
<p>So I guess I am not using the port name correctly. What is the correct way to use the port name in my service?</p>
<p>Thanks in advance,
Abdelghani</p>

<p>The <code>port</code> field represents the port at which the <code>Service</code> object listens to and the <code>targetPort</code> represents the port at which the container is listening.</p>
<p>Try this:</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: banana-service
spec:
  selector:
    app: banana
  ports:
  - port: 8080
    targetPort: bananaport
</code></pre>
