<p>Hope life is great for everyone. I am trying to figure to use named ports for Deployment and Service. For pods and service using named ports works fine. But doesn't for Deployment and Service. I dig and no answers are working, example <a href="https://github.com/GoogleCloudPlatform/k8s-multicluster-ingress/issues/196" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/k8s-multicluster-ingress/issues/196</a> and there is one in Stack Overflow which doesn't helps much, <a href="https://stackoverflow.com/questions/48886837/how-to-make-use-of-kubernetes-port-names">How to make use of Kubernetes port names?</a></p>
<p>This is the YAML files.</p>
<p>deployment-named-port.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test-named-ports
  name: test-named-ports
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-named-ports
  strategy: {}
  template:
    metadata:
      labels:
        app: test-named-ports
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
          name: nginx-port
</code></pre>
<p>named-port-svc.yaml</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: test-named-ports
  ports:
    - port: nginx-port
      targetPort: nginx-port
      nodePort: 30007

vagrant@kubemaster:~$ kubectl apply -f named-port.yaml
deployment.apps/test-nameed-ports created

vagrant@kubemaster:~$ kubectl apply -f named-port-svc.yaml
error: error validating &quot;named-port-svc.yaml&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
</code></pre>
<p>Can someone please help me. Appreciate all your support.</p>
<p>Thanks,</p>
<p>Joe Antony</p>

Celtic Bean
<p>The port and targetPort should <code>80</code> not string <code>nginx-port</code>.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: test-named-ports
  ports:
    - name: nginx-port
      port: 80
      targetPort: 80
      nodePort: 30007

</code></pre>
