Load balancing

GCP provides several types of load balancer as follows:

  • Layer 4 TCP LoadBalancer
  • Layer 4 UDP LoadBalancer
  • Layer 7 HTTP(S) LoadBalancer

The Layer 4 LoadBalancers (both TCP and UDP) are similar to AWS Classic ELB. On the other hand, the Layer 7 HTTP(S) LoadBalancer has content (context)-based routing. For example, the URL/image will forward to instance-a; everything else will forward to instance-b. So, it's more like an application-level LoadBalancer.

AWS also provides Application Load Balancer (ALB or ELBv2), which is quite similar to the GCP Layer 7 HTTP(S) LoadBalancer. For details, please visit https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/.

In order to set up LoadBalancer, and unlike AWS ELB, there are several steps you'll need to follow in order to configure some items beforehand:

Configuration item

Purpose

Instance group

Determine a group of VM instances or a VM template (OS image).

Health check

Set health threshold (interval, timeout, and so on) to determine instance group health status.

Backend service

Set load threshold (maximum CPU or requests per second) and session affinity (sticky session) to the instance group and associate it to health check.

url-maps (LoadBalancer)

This is an actual place-holder to represent an L7 LoadBalancer that associates backend services and targets the HTTP(S) proxy.

Target HTTP(S) proxy

This is a connector that makes relationships between frontend forwarding rules to LoadBalancer.

Frontend forwarding rule

Associate between the Target HTTP proxy and IP address (ephemeral or static) and port number.

External IP (static)

(Optional) allocate a static external IP address for LoadBalancer.

The following diagram is for all of the preceding components' association that constructs the L7 LoadBalancer:

Let's set up an instance group first. In this example, there are three instance groups to create: one for the private hosted Tomcat instance (8080/tcp) and another two instance groups for public HTTP instances for each zone.

To do that, execute the following commands to group three of them:

//create instance groups for HTTP instances and tomcat instance
$ gcloud compute instance-groups unmanaged create http-ig-us-west --zone us-west1-a
$ gcloud compute instance-groups unmanaged create http-ig-us-east --zone us-east1-c
$ gcloud compute instance-groups unmanaged create tomcat-ig-us-west --zone us-west1-a

//because tomcat uses 8080/tcp, create a new named port as tomcat:8080
$ gcloud compute instance-groups unmanaged set-named-ports tomcat-ig-us-west --zone us-west1-a --named-ports tomcat:8080

//register an existing VM instance to correspond instance group
$ gcloud compute instance-groups unmanaged add-instances http-ig-us-west --instances public-on-subnet-a --zone us-west1-a
$ gcloud compute instance-groups unmanaged add-instances http-ig-us-east --instances public-on-subnet-b --zone us-east1-c
$ gcloud compute instance-groups unmanaged add-instances tomcat-ig-us-west --instances private-on-subnet-a --zone us-west1-a
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset