Checkpoint
TCP load balancer with regional forwarding rule
/ 100
Modular Load Balancing with Terraform - Regional Load Balancer
GSP191
Overview
Load balancing on Google Cloud is different from other cloud providers. Google Cloud uses forwarding rules instead of routing instances. These forwarding rules are combined with backend services, target pools, URL maps and target proxies to construct a functional load balancer across multiple regions and instance groups.
Terraform is an open source infrastructure management tool that can simplify the provisioning of load balancers on Google Cloud by using modules.
Objectives
In this lab, you will learn how to:
- Use load balancing modules for Terraform
- Create a regional TCP load balancer
- Create a regional internal TCP load balancer
- Create a global HTTP load balancer with Kubernetes Engine
- Create a global HTTPS content-based load balancer
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Terraform modules overview
The repository you'll use in this lab has some load balancer modules. First you'll learn what the modules are, then you'll clone the repository and use them.
terraform-google-lb (regional forwarding rule)
This module creates a TCP Network Load Balancer for regional load balancing across a managed instance group. You provide a reference to a managed instance group and the module adds it to a target pool. A regional forwarding rule is created to forward traffic to healthy instances in the target pool.
Example snippet:
terraform-google-lb-internal (regional internal forwarding rule)
This module creates an internal load balancer for regional load balancing of internal resources. You provide a reference to the managed instance group and the module adds it to a regional backend service. An internal forwarding rule is created to forward traffic to healthy instances.
Example snippet:
terraform-google-lb-http (global HTTP(S) forwarding rule)
This module creates a global HTTP load balancer for multi-regional content-based load balancing. You provide a reference to the managed instance group, optional certificates for SSL termination, and the module creates the http backend service, URL map, HTTP(S) target proxy, and the global http forwarding rule to route traffic based on HTTP paths to healthy instances.
Example snippet:
Now get started!
Task 1. Clone the examples repository
-
Open a new Cloud Shell tab by clicking on the Activate Cloud Shell icon in the top right corner of the Cloud Console.
-
Run the following command to clone the terraform-google-examples repository:
Task 2. Create a TCP load balancer with a regional forwarding rule
This lab creates a managed instance group with two instances in the same region and a network TCP load balancer.
- Start by exporting your Project ID:
The terraform init
command is used to initialize a working directory containing Terraform configuration files. This command performs several different initialization steps in order to prepare a working directory for use. This command is always safe to run multiple times, to bring the working directory up to date with changes in the configuration.
- Run the
terraform init
command:
Example output:
- In the
terraform-google-lb/examples/basic/variables.tf
file, run the following commands to replace the default region with the lab assigned region of.
The terraform plan
command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files. This command is a convenient way to check whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state. For example, terraform plan
might be run before committing a change to version control, to create confidence that it will behave as expected.
- Run the
terraform plan
command:
- When asked to enter a value for your Project ID, use
.
The terraform apply
command is used to apply the changes required to reach the desired state of the configuration, or the predetermined set of actions generated by a terraform plan execution plan.
- Run the
terraform apply
command:
-
When asked to enter a value for your Project ID, use
. -
Type yes to continue when the next prompt occurs.
Example output:
The instances and load balancer are ready after a few minutes.
-
Check the status of your load balancer in the Cloud Console by navigating to Navigation Menu () > View All Products. Under Networking section, click Network services > Load Balancing.
-
To be able to open the URL of the load balancer in a browser, run the following:
-
Click on the
http://${EXTERNAL_IP}
address in the output to open the link to the load balancer. -
Refresh a few times to observe traffic being balanced across the two instances in the
region.
Click Check my progress to verify the objective.
Congratulations!
In this lab, you learned how to use load balancing modules. Using Terraform, you deployed a regional TCP load balancer, a regional internal TCP load balancer, a global HTTPS load balancer with Kubernetes Engine, and a HTTPS content-based load balancer.
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual last updated July 19, 2024
Lab last tested July 19, 2024
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.