0

I noticed when accessing the Kubernetes Service, the host ip is ignored by the kubernetes.

For example: I have 3 kubernetes workers, hostIP1, hostIP2 and hostIP3, on each worker, i create a pod, with label: app = test. In each pod, it just simple runs python -m SimpleHTTPServer 32000, I then create a service to expose port: 32000 so that it can be accessed outside the cluster.

But when I access http://hostIP1:32000, the traffic is actually routed to any of the hosts, hostIP1, hostIP2 and hostIP3

Is there a way to only let Kubernetes forward traffic to hostIP1 when accessing http://hostIP1:32000?

Thanks

Ping.Goblue
  • 576
  • 8
  • 12

1 Answers1

1

You can't do that. If your pods have the same label, they are going to be selected by the same service, and every time you hit that service it is going to balance the load among the backends it has, which are your pods.

To do what you want, you have to create 3 different services, to point each service to its own backend.

suren
  • 7,817
  • 1
  • 30
  • 51
  • thanks. I figured out a way to do so with `containerPort` and `hostPort` so that the port is only local to the worker node ``` ports: - containerPort: 32000 hostPort: 32000 - containerPort: 32001 hostPort: 32001 ``` – Ping.Goblue Jan 30 '20 at 18:26