Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have one Kubernetes LoadBalancer balance to multiple services?

I have the following services hosted in my Kubernetes cluster on AWS.

  • An nginx server, on ports 80 and 443.
  • A Minecraft server, at port 25565.

Both are working great. I currently have both of them set to type: LoadBalancer, so they both have Elastic Load Balancers that are providing ingress to the cluster.

I would like to have only one ELB -- they cost money, and there's no reason not to have the Minecraft server and the HTTP(S) server on the same external IP.

I tried to create a service without a selector, then tried to manually create an Endpoints object referencing that service, but it doesn't appear to be working. Here's the setup on a gist. When I try and curl on the allocated nodePort from inside the cluster it just hangs.

Is there a way to have one service balance to multiple services?

like image 973
iameli Avatar asked Jan 01 '16 02:01

iameli


2 Answers

The Ingress resource, which was added in version 1.1.0, was designed specifically for this use case. It allows you to put multiple services behind a single IP address, routing to them based on HTTP path. Check out the user guide on it for more details, but feel free to ask if you have more questions about it!

edit: For a non-HTTP(S) service, you can have to find a way to make sure all necessary ports get load balanced by the ELB and then properly routed by Kubernetes. On GCE, you could manually create the load balancer with the ports you need, and then put the load balancer's IP in the externalIPs field for each service. My memory's a little fuzzy, but I don't believe that'll work with an ELB due to its packet rewriting. You might instead want to create each service as a NodePort service, then configure your ELB to forward the packets from the correct external port to the node port for each service.

like image 28
Alex Robinson Avatar answered Oct 20 '22 14:10

Alex Robinson


You could also simply use nginx as a proxy for your minecraft server, and forward traffic from ingress port 25565 to the minecraft server. That way all traffic goes through one Service

like image 196
MrE Avatar answered Oct 20 '22 15:10

MrE