Checkpoints
Create a group of webservers
/ 25
Create a L4 Network Load Balancer that points to the webservers
/ 35
Create a L7 HTTP(S) Load Balancer
/ 40
Setting Up Network and HTTP Load Balancers [ACE]
Overview
In this hands-on lab, you'll learn the differences between a network load balancer and a HTTP load balancer, and how to set them up for your applications running on Google Compute Engine virtual machines.
There are several ways you can load balance in Google Cloud Platform. This lab takes you through the setup of the following load balancers:
Students are encouraged to type the commands themselves, which helps in learning the core concepts. Many labs include a code block that contains the required commands. You can easily copy and paste the commands from the code block into the appropriate places during the lab.
What you'll do
-
Setup a network load balancer.
-
Setup a HTTP(s) load balancer.
-
Get hands-on experience learning the differences between network load balancers and HTTP load balancers.
Prerequisites
Familiarity with standard Linux text editors such as vim
, emacs
, or nano
is helpful.
Setup
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
-
Sign in to Qwiklabs using an incognito window.
-
Note the lab's access time (for example,
1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning. -
When ready, click Start lab.
-
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
-
Click Open Google Console.
-
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges. -
Accept the terms and skip the recovery resource page.
Activate Google Cloud Shell
Google 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.
Google Cloud Shell provides command-line access to your Google Cloud resources.
-
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
-
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- You can list the active account name with this command:
Output:
Example output:
- You can list the project ID with this command:
Output:
Example output:
Task 1. Set the default region and zone for all resources
-
In Cloud Shell, set the default zone:
-
Set the default region:
gcloud
on your own machine, the config
settings persist across sessions. In Cloud Shell you need to set this for every new session or reconnection.
Task 2. Create multiple web server instances
To simulate serving from a cluster of machines, create a simple cluster of Nginx web servers to serve static content using Instance Templates and Managed Instance Groups.
Instance Templates define the look of every virtual machine in the cluster (disk, CPUs, memory, etc). Managed Instance Groups instantiate a number of virtual machine instances using the Instance Template.
To create the Nginx web server clusters, create the following:
-
A startup script to be used by every virtual machine instance to set up a Nginx server upon startup.
-
An instance template to use the startup script.
-
A target pool.
-
A managed instance group using the instance template.
-
Still in Cloud Shell, create a startup script to be used by every virtual machine instance. This script sets up the Nginx server upon startup:
-
Create an instance template, which uses the startup script:
Output:
-
Create a target pool. A target pool allows a single access point to all the instances in a group and is necessary for load balancing in the future steps:
Output:
-
Create a managed instance group using the instance template:
Output:
This creates 2 virtual machine instances with names that are prefixed with nginx-
. This may take a couple of minutes.
-
List the compute engine instances and you should see all of the instances created:
Output:
-
Now configure a firewall so that you can connect to the machines on port 80 via the
EXTERNAL_IP
addresses:
You should be able to connect to each of the instances via their external IP addresses via http://EXTERNAL_IP/
shown as the result of running the previous command.
Check your lab progress. Click Check my progress below to verify that you've created a group of webservers.
Task 3. Create a network load balancer
Network load balancing allows you to balance the load of your systems based on incoming IP protocol data, such as address, port, and protocol type. You also get some options that are not available, with HTTP(S) load balancing. For example, you can load balance additional TCP/UDP-based protocols such as SMTP traffic. And if your application is interested in TCP-connection-related characteristics, network load balancing allows your app to inspect the packets, where HTTP(S) load balancing does not.
-
Create an L4 network load balancer targeting your instance group:
Output:
-
List all Google Compute Engine forwarding rules in your project:
Output:
You can then visit the load balancer from the browser http://IP_ADDRESS/
where IP_ADDRESS
is the address shown as the result of running the previous command.
Check your lab progress. Click Check my progress below to verify that you've created an L4 Network Load Balancer that points to the webservers.
Task 4. Create a HTTP(s) load balancer
HTTP(S) load balancing provides global load balancing for HTTP(S) requests destined for your instances. You can configure URL rules that route some URLs to one set of instances and route other URLs to other instances. Requests are always routed to the instance group that is closest to the user, provided that group has enough capacity and is appropriate for the request. If the closest group does not have enough capacity, the request is sent to the closest group that does have capacity.
-
First, create a health check. Health checks verify that the instance is responding to HTTP or HTTPS traffic.
Output:
-
Define an HTTP service and map a port name to the relevant port for the instance group. Now the load balancing service can forward traffic to the named port.
Output:
-
Create a backend service:
Output:
-
Add the instance group into the backend service:
Output:
-
Create a default URL map that directs all incoming requests to all your instances:
Output:
-
Create a target HTTP proxy to route requests to your URL map:
Output:
-
Create a global forwarding rule to handle and route incoming requests. A forwarding rule sends traffic to a specific target HTTP or HTTPS proxy depending on the IP address, IP protocol, and port specified. The global forwarding rule does not support multiple ports:
Output:
-
After creating the global forwarding rule, it can take several minutes for your configuration to propagate:
Output:
Take note of the http-content-rule IP_ADDRESS for the forwarding rule.
From the browser, you should be able to connect to http://IP_ADDRESS/
. It may take three to five minutes. If you do not connect, wait a minute then reload the browser.
Check your lab progress. Click Check my progress below to verify that you've created an L7 HTTP(S) Load Balancer.
Task 5. Test your knowledge
Test your knowledge about Google cloud Platform by taking our quiz. (Please select multiple correct options if necessary.)
End your lab
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
- 1 star = Very dissatisfied
- 2 stars = Dissatisfied
- 3 stars = Neutral
- 4 stars = Satisfied
- 5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 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.