Home > Blog > Autoscaling with Instance Group and Load Balancing using Google Cloud

Autoscaling with Instance Group and Load Balancing using Google Cloud

Diagram

Today, I’ll build an autoscaling system based on multiple instance groups in two regions. One instance group will be in Singapore, with a maximum number of instances of 2, and another will be in Belgium. Both instance groups have the exact specification based on the same instance template.

The instance template, as its name, is a template to make a new instance. We define the specification of an instance template so that the instance group can replicate the same machine with the same specs, configuration, and things such as startup script.

Instance template

After that, I’ll go to the instance group. An instance group is a group of VM that can replicate based on the specification of the instance group. It can replicate (autoscale) itself based on parameters such as the average CPU usage of the first VM. For example, if the first VM’s average CPU reaches 80%, the instance group will make one more new VM based on the instance template we just defined.

Instance group, Singapore

I’ll create another instance group in Europe (Belgium) with the same configuration as Southeast Asia (Singapore).

Instance group autoscaling configuration

After both instance groups are successfully deployed, I’ll create the load balancer. A load balancer is a reverse proxy for distributing load (traffic) to an instance, and also points traffic to the nearest region where I deployed my instance group.

Since my web application in every instance uses HTTP in port 80, I’ll use an HTTPS load balancer, so this load balancer also acts as an HTTPS (port 443) endpoint. Since it has a single endpoint, I would only need one SSL certificate which is located on the frontend side of the load balancer.

HTTPS Load balancer
SSL certificate chain of the load balancer

After I configured the frontend and backend sides of the load balancer, I’ll access my web application via my domain.

Load balancer’s endpoint, accessed from Singapore

The HTTPS load balancer has successfully been deployed. To make sure that the load balancer points to the closest region, test it with VPN within the Europe region. To make sure that the autoscaling works, test it with multiple connections and look for the instance group panel. After a few minutes, look for the number of instances.

The Singapore instance group is autoscaling

References

Google Cloud External HTTP(S) Load Balancer

Google Cloud Instance Group

Leave a Reply

Your email address will not be published. Required fields are marked *