GCP Cloud Digital Leader Certification
GCP Compute Part 2
Demo Load Balancer
Hello, and welcome back to this article.
In this guide, we will walk you through configuring a load balancer on Google Cloud Platform (GCP) and explain the essential concepts behind each step.
Setting Up the Instance Group
Begin by logging into the GCP console and selecting the appropriate project. Navigate to the Compute section by entering "Compute" in the console search bar. On the Compute page, create an instance group as outlined below.
- Click on the Instance Groups section.
- Select the option to create a new instance group.
- Name the group to reflect its purpose (e.g., "load balancing") and choose an appropriate instance template. This template, which outlines the configuration for your instances, will be reused throughout this demonstration.
- Adjust the autoscaling settings: set the maximum number of instances to two instead of the default ten, since this demonstration does not require a high scale.
Instance Group Interface Overview
Review the instance group creation interface to familiarize yourself with the available options, including naming the group, providing a description, selecting an instance template, and choosing the target region.
After confirming the settings, accept the default location and other configuration settings. Ensure that the autoscaling settings have been adjusted as described, then click "Create" to provision your instance group.
Creating the Load Balancer
With the instance group in place, the next step is to create a load balancer. While it is possible to attach multiple instance groups to a load balancer, this demonstration uses a single instance group for simplicity.
To locate the load balancing service:
- Use the scroll menu on the left side of the GCP console.
- Alternatively, search for “load balancing” in the search bar.
GCP organizes load balancing under Network Services, alongside features like VPC firewall rules.
Once in the load balancing section, click on "Create Load Balancer." GCP will present three types of load balancers:
- HTTPS Load Balancing (Layer 7)
- TCP Load Balancing (Layer 4)
- UDP Load Balancing (Layer 4)
Since HTTPS load balancing is the most common and operates at Layer 7 over TCP, click "Start Configuration" under the HTTP load balancer option.
When prompted, specify the purpose of your load balancer:
- Choose between "internet-facing" (for external access) and "internal-facing" (for internal communication only).
For this demonstration, select the internet-facing option. Then, choose between a global HTTPS load balancer, a classic load balancer, or a regional load balancer. For simplicity, proceed with the default configuration and click "Continue." Provide a name for your load balancer (e.g., "HTTP Load Balancer") and confirm that the frontend will listen on port 80.
Configuring the Backend Service
Proceed to the "Backend" section to define where the load balancer should route incoming traffic:
- Click on the drop-down menu and select "Create a backend service."
- Fill in the details:
- Assign a name to the backend service (e.g., "load balancer backend service").
- Select the instance group created earlier.
- Configure the port to 80.
If you plan to use additional instance groups, you can click "Add a backend." For this demonstration, proceed with a single backend and click "Cancel" when prompted to add another.
Note
At this stage, no service is running on port 80 of your instance group, so any incoming traffic will not reach an active service. Further automation and software installation will be covered in subsequent articles.
Setting Up the Health Check
Scroll down to set up a health check, which is critical to monitor the status of your backend instances. Create a health check (for example, name it "simple health check") that will attempt to access port 80. Because there is currently no service running on port 80, the health check will fail. This is expected and will be rectified once the necessary application is deployed.
Optionally, you can configure a security policy using Cloud Armor. For now, leave the security settings as default and click "Create." Confirm any prompts by clicking "OK" to finalize the backend service configuration.
Configuring Routing Rules
Next, define the routing rules that determine how incoming traffic is directed to your backend:
- Navigate to the routing rules dialog.
- Specify host and path rules if you need to direct specific URL patterns (e.g., traffic ending with "/payment" can be assigned to a dedicated backend).
- For this demonstration, use the default routing rule.
- Click "Create" to finalize the load balancer configuration.
After creation, the load balancer generates a unique URL. However, if you access it immediately, you might see a "no healthy upstream" error because the backend instance is not yet serving content on port 80.
Verifying Health Checks and Load Balancer Status
After connecting the load balancer to your instance group, you may notice that the backend is flagged as unhealthy. To troubleshoot:
- Click on the health check settings to review the configuration.
- Verify that the health check is attempting to access port 80 on your instance group.
Once the necessary application is deployed and listens on port 80, the health check will succeed, and the load balancer will start routing traffic appropriately.
Clean-Up and Conclusion
After completing this demonstration, it is important to clean up unused resources to avoid unnecessary charges. Follow these steps:
- Delete the load balancer along with its associated health check.
- Remove the instance group from the Compute section.
This concludes our demo on setting up a load balancer on Google Cloud Platform. In future articles, we will explore automation processes to install and update software on your instance group, ensuring your applications become fully operational once deployed.
Thank you for reading, and we look forward to guiding you in the next article.
Watch Video
Watch video content