Can I make calls directly to pods from outside Kubernetes?

4/22/2016

I'm attempting to transition existing applications to Kubernetes that work as follows:

  • An outside service calls our application through a load balancer with a new session.
  • Our application returns the ip of the server that processed the request.
  • All subsequent calls from the outside service for that session are made directly to the same server (bypassing the load balancer)

Is there any way to do this in kubernetes? I understand that pod ip's are not exposed externally, is there some way to expose them directly?

Also, I don't think I can use sessionAffinity="ClientIP" because the requests will all come in from the same place. Is there a way to write custom sessionAffinity type?

-- Jason B
kubernetes

1 Answer

4/22/2016

It kind of depends on how your network is set up and what you mean by an "outside service", but the answer is most likely "no".

If you're running using one of the default cluster creation scripts in a cloud environment, pod IP addresses are not routable from the Internet, so any service not in the same private network as your cluster won't be able to talk directly to pods.

However, depending on what cloud provider you're on, you'll likely get the behavior that you want anyways by just continuing to make all calls through to the external IP of a service of type LoadBalancer. For instance, on the Google Cloud Platform, the cloud load balancer that gets created for such services by default maintains connection affinity by 5-tuple (src ip and port, dst ip and port, L4 protocol), which sounds like it's what you want, since you want balancing per session rather than per IP.

As for creating a new sessionAffinity type, that's not an easy thing to extend, since it requires changing Kubernetes source code. If that's really a path you want to take, it's likely that you'd want to run your own load balancer within your cluster rather than relying on the built-in load balancing.

-- Alex Robinson
Source: StackOverflow