<p><a href="https://i.stack.imgur.com/A2G76.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A2G76.png" alt="enter image description here" /></a></p>
<p>The nodeport takes in 3 parameters in the service yaml.</p>
<ul>
<li>port</li>
<li>targetPort</li>
<li>nodePort</li>
</ul>
<p>Since all you wanted was to map a port on the node(nodeport) to the port on the container(targetPort), why do we need to provide the port of the service?</p>
<p>Is this because Nodeport is internally implemented <strong>on top of</strong> ClusterIP?</p>

<p>&quot;Nodeport is internally implemented on top of ClusterIP&quot; - correct.</p>
<p>The port in the Kubernetes Service definition is used to specify the port on which the service will listen for traffic within the Kubernetes cluster. This is the port that will be exposed to other pods in the cluster as an endpoint for the service. When a request is made to this port by a client within the cluster, the traffic will be routed to one of the pods selected by the Service based on its load balancing algorithm.</p>
<p>The nodePort is used to expose the service on a port on the node itself, which allows the service to be accessed from outside the cluster.</p>
