0

I created a nodeport service on a port 12345, to access my api running on node 6666, deployed through a pod. The pod is deployed in multiple nodes.

 ports:
   - port: 8181
     targetPort: 6666
     nodePort: 12345
     protocol: TCP

In order to get the ip of the node, by running

   kubectl get nodes -o wide

the internal / external ip of the node was obtained. Thus, the resulting curl command is

   http://<node internal ip>:12345/

The issue is that this is circulating all the nodes, running through the open port, everytime a ping is done.

How can I ensure that the ping, using the internal ip only hits one node and the pod service running on it?

Thanks in advance.!!

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92
  • It's not clear what you are asking. Are you asking how to reduce the number of hops you see when you run the `ping` command against your node? – jordanm Aug 31 '23 at 23:14
  • I have a pod running an api endpoint, deployed on multiple nodes. I declared a service as nodeport, to open the nodes for communication, so that I can ping the api, through the defined port (12345). The issue I faced was during the ping, it did not stick to the specific node, where the ip was mentioned, rather accessed all the nodes the pod-api was deployed on @jordanm – Lakshmi Narayanan Aug 31 '23 at 23:34

1 Answers1

0

I was able to solve the above issue by adding the

 externalTrafficPolicy: "Local"

In the service definition. This way, the ping to the ip of the node, and to the api, did not go to other nodes, but rather was restricted locally to the node.

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92