Traffic Distribution Management with GCP’s Internal HTTP Load Balancer

Traffic Distribution Management with GCP’s Internal HTTP Load Balancer In this lab we are going to deploy the following diagram infraestracture: The principal idea will be to use a Regional Internal HTTP Load Balancer [my-ilb] to forward tr


In this lab we are going to deploy the following diagram infraestracture:

The principal idea will be to use a Regional Internal HTTP Load Balancer [my-ilb] to forward traffic using and advanced forwarding rule to weight the backends to recibe a % of the traffic.

HTTP(S) Load Balancer in GCP

An HTTP(S) Load Balancer in Google Cloud Platform (GCP) is a fully distributed, software-defined managed service that is designed to handle huge amounts of traffic. It can run at the global level, meaning it can route traffic to the closest regional instance based on the geographic location of the client reducing latency.

One key feature is that will be makeing use in this lab is that it supports advanced traffic management strategies such as URL maps, which allow requests to be routed to different backends based on the request path, and also supports content-based routing.

This LB is a GCP’s Managed Service based on the open-source Envoy proxy

Lab Resources

Will be using the “my-internal-app” VPC. This network has 2 subnets already created:

  • Subnet-a: 10.10.20.0/24
  • Subnet-b: 10.10.30.0/24

This network has Firewall rules configured in order to run the lab.

be aware to enable/allow this traffic if you do the lab!

We’ll use the following Compute Engine resources:

  • Instance-group-1: will be the “blue-service” backend
  • Instance-group-2: will be the “green-service” backend
  • Utility-vm: will be using this vm to consume the instance services through the HTTP load balancer.

If we run a Curl cmd to the vms will find the following responses:

This will let us know how the Load Balancing is working to know the hostname in the backend responses.

HTTP Load Balancer creation

Now we’ll go through the Load Balancer creation using the GCP Console.

Create and configure Load Balancer

Now we’ll going through the Regional Internal HTTP Load Balancer creation. This type of Load Balancer in GCP its a OSI Layer 7 traffic for HTTP and HTTPs applications. It also supports HTTP/2 protocol.

  • First of all will search for “Load Balancing” in the “Network services” section in our GCP Console.
  • Then will click on “Create” and we are going to select the “Application Load Balancer” option.
  • We are going to set it as internal selection the Highlighted option in the image above.
  • Now we are going to connect it to the “my-internal-app” VPC.
  • Here the LB will ask us to reserve a Subnet for its use.
  • Reserve the subnet.
  • The proxy-only subnet will be created:

Create backends

Now we’ll have to create the backends:

  • Select “Create Backend Service”:
  • Now we’ll create the “Blue-service” backend asociated to the MIG-1.
  • Configure the Instance Group, and the port number “80” for HTTP.
  • We need to create the Health Check in order for the Load Balancer to be able to monitor the backend service and tell us the health.
  • Specify the TCP 80 port. Also change the Highlighted areas in the “Health Criteria” section.
  • Click on “Create”.

Now we repeat the same backend generation process for our Instance-Group-2, we’ll call it green-service.

  • After the creation of the 2nd backend service. We’ll select both for the backend configuration in the LB:

Routing Rules

Now we are going to configure the Routing Rules. As i wrote erlier in the post, we are going to configure an advanced rule to weight the backends.

  • First of all we are going to click on the Routing Rules section in the Load Balancer configuration wizard.
  • Then we are going to select the “Advanced host and path rule” Mode.
  • And we are going to configure the following yaml-formated rule:

https://github.com/mdiloreto/gcp-lb-advanced-configs/blob/main/weight/weighted_backend.txt

YAML
defaultService: projects/{proj-name}/regions/{region}/backendServices/{backend}
name: matcher1
routeRules:
- matchRules:
- prefixMatch: /
priority: 0
routeAction:
weightedBackendServices:
- backendService:projects/{proj-name}/regions/{region}/backendServices/{backend}
weight: 70
- backendService: projects/{proj-name}/regions/{region}/backendServices/{backend}
weight: 30

We must replaces the Services fully-qualified names with our own.

What does this yaml rule does?

  • defaultService: This specifies the default backend service that the load balancer should use if none of the route rules match the incoming request. The backend service is identified by a path that includes the project name ({proj-name}), region ({region}), and the backend service name ({backend}).
  • name: This is simply a name given to the matcher, in this case, matcher1.
  • routeRules: defines a set of rules for routing incoming requests to backend services.
  • matchRules: list of rules that determine how the load balancer matches an incoming request to a route rule.
  • prefixMatch: indicates that the rule should match any request because is the root path.
  • priority: This sets the priority of the rule. Since it's set to 0, this rule has the highest priority (the lower the number, the higher the priority).
  • routeAction: This defines what action to take when a match is found.
  • weightedBackendServices: This is a list of backend services and their associated weights. When multiple backend services are listed, the weights determine how traffic is distributed among them.
  • The first backend service is assigned a weight of 70, meaning it will receive approximately 70% of the traffic.
  • The second backend services assigned a weight of 30, so it will receive approximately 30% of the traffic.

Then click in “Done”.

What is the “Default rule”? Its an required rule that will take action for any unmatched host. We’ll configure Blue-service as our default.

Frontend configuration

To end our configuration we’ll configure a internal private IP on the frontend of our load balancer. All the request will be redirected to this IP. In a production enviroment will only recieve the traffic through this services and will block/disable any direct traffic to our backends.

  • Configure the private ip 10.10.30.5 with HTTP trafic on port 80
  • Now review and finalize:

Test traffic

Now we send the traffic directly to the Load Balancer and we can see that our rule is working!

Thanks for reading. The learning continues in the next article.