Checkpoints
Configure HTTP and health check firewall rules
/ 25
Configure instance templates and instance group
/ 25
Configure the HTTP Load Balancer
/ 25
Blacklist the siege-vm
/ 25
HTTP Load Balancer with Cloud Armor
GSP215
Overview
Google Cloud HTTP(S) load balancing is implemented at the edge of Google's network in Google's points of presence (POP) around the world. User traffic directed to an HTTP(S) load balancer enters the POP closest to the user and is then load balanced over Google's global network to the closest backend that has sufficient capacity available.
Cloud Armor IP allowlist/denylist enable you to restrict or allow access to your HTTP(S) load balancer at the edge of the Google Cloud, as close as possible to the user and to malicious traffic. This prevents malicious users or traffic from consuming resources or entering your virtual private cloud (VPC) networks.
In this lab, you configure an HTTP Load Balancer with global backends, as shown in the diagram below. Then, you stress test the Load Balancer and denylist the stress test IP with Cloud Armor.
Objectives
In this lab, you learn how to perform the following tasks:
-
Create HTTP and health check firewall rules
-
Configure two instance templates
-
Create two managed instance groups
-
Configure an HTTP Load Balancer with IPv4 and IPv6
-
Stress test an HTTP Load Balancer
-
Denylist an IP address to restrict access to an HTTP 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 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 Console. 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 from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost 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 Cloud Console opens in this tab.
Task 1. Configure HTTP and health check firewall rules
Configure firewall rules to allow HTTP traffic to the backends and TCP traffic from the Google Cloud health checker.
Create the HTTP firewall rule
Create a firewall rule to allow HTTP traffic to the backends.
-
In the Cloud Console, navigate to Navigation menu (
) > VPC network > Firewall.
-
Notice the existing ICMP, internal, RDP, and SSH firewall rules.
Each Google Cloud project starts with the default network and these firewall rules.
-
Click Create Firewall Rule.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name default-allow-http Network default Targets Specified target tags Target tags http-server Source filter IPv4 Ranges Source IPv4 ranges 0.0.0.0/0 Protocols and ports Specified protocols and ports, and then check TCP, type: 80
Make sure to include the /0 in the Source IPv4 ranges to specify all networks.
-
Click Create.
Create the health check firewall rules
Health checks determine which instances of a load balancer can receive new connections. For HTTP load balancing, the health check probes to your load balanced instances come from addresses in the ranges 130.211.0.0/22
and 35.191.0.0/16
. Your firewall rules must allow these connections.
-
Still in the Firewall page, click Create Firewall Rule.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name default-allow-health-check Network default Targets Specified target tags Target tags http-server Source filter IPv4 Ranges Source IPv4 ranges 130.211.0.0/22
,35.191.0.0/16
Protocols and ports Specified protocols and ports, and then check TCP Note: Make sure to enter the two Source IPv4 ranges one-by-one and press SPACE in between them. -
Click Create.
Click Check my progress to verify the objective.
Task 2. Configure instance templates and create instance groups
A managed instance group uses an instance template to create a group of identical instances. Use these to create the backends of the HTTP Load Balancer.
Configure the instance templates
An instance template is an API resource that you use to create VM instances and managed instance groups.
Instance templates define the machine type, boot disk image, subnet, labels, and other instance properties.
Create one instance template for
-
In the Cloud Console, navigate to Navigation menu (
) > Compute Engine > Instance templates, and then click Create instance template.
-
For Name, type
-template. NOTE: An instance template name can not have "space" in the name, remove any extra space if required. -
For Series, select E2.
-
For Machine Type, select e2-micro.
-
Click Advanced Options.
-
Click Networking. Set the following value and leave all other values at their defaults:
Property Value (type value or select option as specified) Network tags http-server -
Click default under Network interfaces. Set the following values and leave all other values at their defaults:
Property Value (type value or select option as specified) Network default Subnetwork default ( ) Click Done.
The network tag http-server ensures that the HTTP and Health Check firewall rules apply to these instances.
-
Click the Management tab.
-
Under Metadata, click + ADD ITEM and specify the following:
Key Value startup-script-url gs://cloud-training/gcpnet/httplb/startup.sh
The startup-script-url
specifies a script that executes when instances are started. This script installs Apache and changes the welcome page to include the client IP and the name, region, and zone of the VM instance. Feel free to explore this script.
- Click Create.
- Wait for the instance template to be created.
Now create another instance template for subnet-b by copying
-
Click on
-template and then click on the +CREATE SIMILAR option from the top. -
For Name, type europe-west1-template.
-
Click Advanced Options.
-
Click Networking.
-
Ensure http-server is added as a network tag.
-
In Network interfaces, for Subnetwork, select default (europe-west1).
-
Click Done.
-
Click Create.
Create the managed instance groups
Create a managed instance group in
-
Still in Compute Engine, click Instance groups in the left menu.
-
Click Create instance group.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name -mig (if required, remove extra space from the name) Location Multiple zones Region Instance template -template Minimum number of instances 1 Maximum number of instances 2 Autoscaling signals > Click dropdown > Signal type CPU utilization Target CPU utilization 80, click Done. Cool-down period 45
Managed instance groups offer autoscaling capabilities that allow you to automatically add or remove instances from a managed instance group based on increases or decreases in load. Autoscaling helps your applications gracefully handle increases in traffic and reduces cost when the need for resources is lower. You just define the autoscaling policy and the autoscaler performs automatic scaling based on the measured load.
- Click Create.
Now repeat the same procedure to create a second instance group for europe-west1-mig in europe-west1:
-
Click Create Instance group.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name europe-west1-mig Location Multiple zones Region europe-west1 Instance template europe-west1-template Minimum number of instances 1 Maximum number of instances 2 Autoscaling signals > Click dropdown > Signal type CPU utilization Target CPU utilization 80, click Done. Cool-down period 45 -
Click Create.
Click Check my progress to verify the objective.
Verify the backends
Verify that VM instances are being created in both regions and access their HTTP sites.
-
Still in Compute Engine, click VM instances in the left menu.
-
Notice the instances that start with
-mig and europe-west1-mig
.These instances are part of the managed instance groups.
-
Click on the External IP of an instance of
-mig. You should see the Client IP (your IP address), the Hostname (starts with
-mig) and the Server Location (a zone in ). -
Click on the External IP of an instance of
europe-west1-mig
.You should see the Client IP (your IP address), the Hostname (starts with
europe-west1-mig
) and the Server Location (a zone in europe-west1).
Task 3. Configure the HTTP Load Balancer
Configure the HTTP Load Balancer to balance traffic between the two backends (us-east1-mig in us-east1 and europe-west1-mig in europe-west1), as illustrated in the network diagram:
Start the configuration
-
In the Cloud Console, click Navigation menu (
) > click Network Services > Load balancing, and then click Create load balancer.
-
Under HTTP(S) Load Balancing, click on Start configuration.
-
Select From Internet to my VMs or serverless services, and click Continue.
-
Set the New HTTP(S) Load Balancer Name to
http-lb
.
Configure the frontend
The host and path rules determine how your traffic will be directed. For example, you could direct video traffic to one backend and static traffic to another backend. However, you are not configuring the Host and path rules in this lab.
-
Click on Frontend configuration.
-
Specify the following, leaving all other values at their defaults:
Property Value (type value or select option as specified) Protocol HTTP IP version IPv4 IP address Ephemeral Port 80 -
Click Done.
-
Click Add Frontend IP and port.
-
Specify the following, leaving all other values at their defaults:
Property Value (type value or select option as specified) Protocol HTTP IP version IPv6 IP address Auto-allocate Port 80 -
Click Done.
HTTP(S) load balancing supports both IPv4 and IPv6 addresses for client traffic. Client IPv6 requests are terminated at the global load balancing layer, then proxied over IPv4 to your backends.
Configure the backend
Backend services direct incoming traffic to one or more attached backends. Each backend is composed of an instance group and additional serving capacity metadata.
-
Click on Backend configuration.
-
For Backend services & backend buckets, click Create a backend service.
-
Set the following values, leave all other values at their defaults:
Property Value (select option as specified) Name http-backend Instance group -mig Port numbers 80 Balancing mode Rate Maximum RPS 50 Capacity 100
This configuration means that the load balancer attempts to keep each instance of us-east1-mig at or below 50 requests per second (RPS).
-
Click Done.
-
Click Add backend.
-
Set the following values, leave all other values at their defaults:
Property Value (select option as specified) Instance group europe-west1-mig Port numbers 80 Balancing mode Utilization Maximum backend utilization 80 Capacity 100
This configuration means that the load balancer attempts to keep each instance of europe-west1-mig at or below 80% CPU utilization.
-
Click Done.
-
For Health Check, select Create a health check.
-
Set the following values, leave all other values at their defaults:
Property Value (select option as specified) Name http-health-check Protocol TCP Port 80
Health checks determine which instances receive new connections. This HTTP health check polls instances every 5 seconds, waits up to 5 seconds for a response and treats 2 successful or 2 failed attempts as healthy or unhealthy, respectively.
-
Click Save.
-
Check the Enable Logging box.
-
Set the Sample Rate to
1
. -
Click Create to create the backend service.
-
Click Ok.
Review and create the HTTP Load Balancer
- Click on Review and finalize.
- Review the Backend and Frontend services.
- Click on Create.
- Wait for the load balancer to be created.
- Click on the name of the load balancer (http-lb).
- Note the IPv4 and IPv6 addresses of the load balancer for the next task. They will be referred to as
[LB_IP_v4]
and[LB_IP_v6]
, respectively.
Click Check my progress to verify the objective.
Task 4. Test the HTTP Load Balancer
Now that you created the HTTP Load Balancer for your backends, verify that traffic is forwarded to the backend service.
Access the HTTP Load Balancer
To test IPv4 access to the HTTP Load Balancer, open a new tab in your browser and navigate to http://[LB_IP_v4]
. Make sure to replace [LB_IP_v4]
with the IPv4 address of the load balancer.
If you have a local IPv6 address, try the IPv6 address of the HTTP Load Balancer by navigating to http://[LB_IP_v6]
. Make sure to replace [LB_IP_v6]
with the IPv6 address of the load balancer.
Stress test the HTTP Load Balancer
Create a new VM to simulate a load on the HTTP Load Balancer using siege
. Then, determine if traffic is balanced across both backends when the load is high.
-
In the Console, navigate to Navigation menu (
) > Compute Engine > VM instances.
-
Click Create instance.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name siege-vm Region us-central1 Zone us-central1-a Series E2
Given that us-central1 is closer to
-
Click Create.
-
Wait for the siege-vm instance to be created.
-
For siege-vm, click SSH to launch a terminal and connect.
-
Run the following command, to install siege:
-
To store the IPv4 address of the HTTP Load Balancer in an environment variable, run the following command, replacing
[LB_IP_v4]
with the IPv4 address:
-
To simulate a load, run the following command:
- In the Cloud Console, on the Navigation menu (
), click Network Services > Load balancing.
- Click Backends.
- Click http-backend.
- Navigate to http-lb.
- Click on the Monitoring tab.
- Monitor the Frontend Location (Total inbound traffic) between North America and the two backends for 2 to 3 minutes.
At first, traffic should just be directed to
This demonstrates that by default traffic is forwarded to the closest backend but if the load is very high, traffic can be distributed across the backends.
- Return to the SSH terminal of siege-vm.
- Press CTRL+C to stop siege if it's still running.
The output should look like this:
Task 5. Denylist the siege-vm
Use Cloud Armor to denylist the siege-vm from accessing the HTTP Load Balancer.
Create the security policy
Create a Cloud Armor security policy with a denylist rule for the siege-vm.
- In the console, navigate to Navigation menu (
) > Compute Engine > VM instances.
- Note the External IP of the siege-vm. This will be referred to as
[SIEGE_IP]
.
-
In the Cloud console, navigate to Navigation menu > Network Security > Cloud Armor.
-
Click Create policy.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name denylist-siege Default rule action Allow -
Click Next step.
-
Click Add rule.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Condition > Match Enter the SIEGE_IP Action Deny Deny status 403 (Forbidden) Priority 1000 -
Click Done.
-
Click Next step.
-
Click Add Target.
-
For Type, select Load balancer backend service.
-
For Target, select http-backend.
-
Click Create policy.
- Wait for the policy to be created before moving to the next step.
Click Check my progress to verify the objective.
Verify the security policy
Verify that the siege-vm cannot access the HTTP Load Balancer.
-
Return to the SSH terminal of siege-vm.
-
To access the load balancer, run the following:
The output should look like this:
- Open a new tab in your browser and navigate to
http://[LB_IP_v4]
. Make sure to replace[LB_IP_v4]
with the IPv4 address of the load balancer.
-
Back in the SSH terminal of siege-vm, to simulate a load, run the following command:
The command will not generate any output.
Explore the security policy logs to determine if this traffic is also blocked.
- In the console, navigate to Navigation menu > Network Security > Cloud Armor.
- Click denylist-siege.
- Click Logs.
- Click View policy logs.
- On the Logging page, make sure to clear all the text in the Query preview. Select resource to Cloud HTTP Load Balancer > http-lb-forwarding-rule > http-lb then click Apply.
- Now click Run Query.
- Expand a log entry in Query results.
- Expand httpRequest.
The request should be from the siege-vm IP address. If not, expand another log entry.
- Expand jsonPayload.
- Expand enforcedSecurityPolicy.
- Notice that the configuredAction is to
DENY
with the namedenylist-siege
.
Cloud Armor security policies create logs that can be explored to determine when traffic is denied and when it is allowed, along with the source of the traffic.
Congratulations!
You configured an HTTP Load Balancer with backends in
Finish your quest
This self-paced lab is part of the Networking Fundamentals in Google Cloud quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest or any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.
Take your next lab
Continue your quest with Create an Internal Load Balancer, or check out these suggestions:
Next steps / Learn more
For information on the basic concepts of Cloud Armor, see Cloud Armor Documentation.
For more information on Load Balancing, see Load Balancing.
Manual Last Updated April 04, 2023
Lab Last Tested April 04, 2023
Copyright 2023 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.