Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP Load Balancer with multiple applications and ports

I am struggling to get the load balancer to work with more than one application. My setup:

Applications: Web1 (Port 10000), Web2 (Port 11000), Web3 (Port 12000)
Servers: Serv1, Serv2, Serv3.

All servers are identical and have Web1, Web2 and Web3 listening on port: 10000, 11000, 12000 respectively.

How can I instruct the load balancer to do the following:

web1.domain.com -----> use Serv1,Serv2,Serv3 port 10000. 
web2.domain.com -----> use Serv1,Serv2,Serv3 port 11000. 
web3.domain.com -----> use Serv1,Serv2,Serv3 port 12000.

I managed to get it working with 1 application but I can't create 3 load balancers as the servers already belongs to a different instance group.

I have read about the port name mapping, but the load balancer keeps ignoring those and uses its own generated one called 'http'.

Has anyone faced any similar issues?

like image 455
lvandyk Avatar asked Mar 07 '23 07:03

lvandyk


1 Answers

If you setup those three different backend ports as named ports in the instance group containing those three servers, this setup should work. I've given it a try, setting up an Apache webserver listening on three different ports, and it worked.

Here's the steps I took to have a setup like the one you're describing working correctly:

  1. I put three different servers in one instance group;
  2. In that instance group, I added the ports used by the applications as named ports. Using gcloud, try running this command: gcloud compute instance-groups set-named-ports "NAME_OF_INSTANCE_GROUP" --zone "INSTANCE_GROUP_ZONE" --named-ports "port0:10000,port1:11000,port2:12000";
  3. Create three different backends from the same instance group, one for each port. Make sure they're all using a different named port. Using gcloud, make sure you set the --port-name argument to one of the named ports of the instance group;
  4. In the load-balancer you want to create, define two "Host and Path rules" (URL Maps) besides the default one. These additional rules should match requests for one of the three hostnames you've mentioned, should match all paths for that host, and should point to the correct backend. So for instance, one of these rules should go like "Host: web2.domain.com, Path: /*, Backend: backend_using_port1";
  5. The frontend can be whatever you want, I pretty much left the default settings.

Following these steps, I got a load-balancer that was capable of reaching the same instance group in three different ports simply using three different DNS hostnames.

Be aware that there are important restrictions to this kind of setup, with the more relevant restrictions being:

  • Both backends must use the same balancing mode, either UTILIZATION or RATE.
  • You can use maxRatePerInstance and maxRatePerGroup together. It is acceptable to set one backend to use maxRatePerInstance and the other to maxRatePerGroup.
  • If your instance group serves two or more ports for several backends respectively, you have to specify different port names in the instance group.

Finally, you can test this setup out using curl:

curl --resolve "web3.domain.com:FRONTEND_PORT:PUBLIC_IP_OF_LB" http://web3.domain.com/
like image 165
Lopson Avatar answered Apr 27 '23 06:04

Lopson