<p>When a container runs on a machine, one has to specify the port on which it should run, so other services in the machine can access to this container via port.
But in <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">kubernetes</a>, each pod has their own IP address and user can mention incoming port, so other pods can communicate via IP:Port address. </p>

<p>So what is the need for having target port. I feel one can set any port for "target port" field and the other pods will be seamlessly able to communicate with it.</p>

Vineet Mimrot
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
  - port: 8080
    targetPort: 8070
    nodePort: 31222
    protocol: TCP 
  selector:
    component: my-service-app
</code></pre>

<p>port:  is the port used by the k8s service </p>

<p>target port:  is the port on which the pod is serving the app</p>

<p>nodePort:  is the port on which the service is exposed outside the cluster </p>
