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

Question:

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?

Answer:

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

Leave a Reply