Question 10 at Mock Exam1 : Expose the `hr-web-app` as service `hr-web-app-servi . . .

Question 10 at Mock Exam1 : Expose the hr-web-app as service hr-web-app-service application on port 30082 on the nodes on the cluster.
The web application listens on port 8080

What I did: kubectl expose deployment hr-web-app --type=NodePort --name=hr-web-app-service --port=8080 --target-port=30082

What the solution says: Run the command: kubectl expose deployment hr-web-app --type=NodePort --port=8080 --name=hr-web-app-service --dry-run=client -o yaml > hr-web-app-service.yaml to generate a service definition file. Then edit the nodeport in it and create a service.

I see that I don’t understand the difference between port , targetport and nodeport. Can anyone help me to understand that?

Mayur Sharma:
Think the port in prespective of a service, port is
• nodePort: The service exposes this port on node to end users
• port: the service uses this port to set communication b/w service and pod
• targetPort: port of the pod that service targets to forward traffic.
hope it helps.

Madhan Kumar:
‘node port’ is a port on the node -> ‘port’ is the port on the service -> ‘taregetport’ is the port on the container .

Fernando Jimenez:
When declaring a service, it helps as well to do it, always, from the perspective of the service. I am the service and --port is my port as a service. --target-port is the container I need to transfer the request to. And the nodePort, in the range of 30000-32767, is the port that the hosting machine is accepting request, the origin I got the request from. This one you can not declare with expose

thanks for your answers!