arrow_back

Configuring an HTTP Load Balancer with Google Cloud Armor

로그인 가입
700개 이상의 실습 및 과정 이용하기

Configuring an HTTP Load Balancer with Google Cloud Armor

실습 2시간 universal_currency_alt 크레딧 5개 show_chart 입문
info 이 실습에는 학습을 지원하는 AI 도구가 통합되어 있을 수 있습니다.
700개 이상의 실습 및 과정 이용하기

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.

Google Cloud Armor IP deny/allow rules 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 will configure an HTTP load balancer with global backends, as shown in the diagram below. Then you stress test the load balancer and deny the stress test IP with Google Cloud Armor.

Network architecture diagram of an HTTP load balancer with global backends

Objectives

In this lab, you will learn how to perform the following tasks:

  • Create a health check firewall rule
  • Create two regional NAT configurations using Cloud Router
  • Configure two instance templates
  • Create two managed instance groups
  • Configure an HTTP load balancer with IPv4 and IPv6
  • Stress test an HTTP load balancer
  • Deny an IP address to restrict access to an HTTP load balancer

Setup and requirements

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Sign in to Qwiklabs using an incognito window.

  2. 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.

  3. When ready, click Start lab.

  4. Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.

  5. Click Open Google Console.

  6. 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.

  7. 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.

  1. In Cloud console, on the top right toolbar, click the Open Cloud Shell button.

    Highlighted Cloud Shell icon

  2. 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:

Project ID highlighted in the Cloud Shell Terminal

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:
gcloud auth list

Output:

Credentialed accounts: - @.com (active)

Example output:

Credentialed accounts: - google1623327_student@qwiklabs.net
  • You can list the project ID with this command:
gcloud config list project

Output:

[core] project =

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: Full documentation of gcloud is available in the gcloud CLI overview guide .

Task 1. Configure a health check firewall rule

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.

Create the HTTP firewall rule

Create a firewall rule to allow HTTP traffic to the backends.

  1. In the Cloud console, navigate to Navigation menu (Navigation menu icon) > VPC network > Firewall.

  2. Notice the existing ICMP, internal, RDP, and SSH firewall rules.

    Each Google Cloud project starts with the default network and these firewall rules.

  3. Click Create Firewall Rule.

  4. 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.

  1. Click Create.

Create the health check firewall rules

Health checks determine which instances of a load balancer can receive new connections. For Application 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.

  1. Still in the Firewall policies page, click Create Firewall Rule.

  2. 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.
  3. Click Create.

Click Check my progress to verify the objective. Configure health check firewall rule

Task 2. Create two NAT configurations using Cloud Router

The Google Cloud VM backend instances that you set up in task 3 will not be configured with external IP addresses.

Instead, you will set up the Cloud NAT service to allow these VM instances to make outbound requests in order to install Apache Web server and PHP when they are launched. You create a Cloud Router for each managed instance group, one in and one in the region, which you will configure in the next task.

Create the Cloud Router instance

  1. In the Cloud Console, in the Navigation menu (Navigation menu icon) click View All Products and navigate to Network services > Cloud NAT.

  2. Click Get started.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Gateway name nat-1
    Network default
    Region
  4. Click Cloud Router and select Create new router.

  5. For Name, type nat-router-1.

  6. Click Create.

  7. In Create a cloud NAT gateway, click Create.

Note: Wait until the NAT Gateway Status changes to Running before moving onto the next task.

Repeat the same procedure for nat-2.

  1. Click Create Cloud NAT Gateway.

  2. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Gateway name nat-2
    Network default
    Region
    Cloud Router > Create new router Specify the name nat-router-2
  3. Click Create.

  4. In Create a NAT gateway, click Create.

Click Check my progress to verify the objective. Create two NAT configurations using Cloud Router

Task 3. Configure an instance template and create instance groups

A managed instance group uses an instance template to create a group of identical instances. You will use these to create the backends of the HTTP load balancer.

Configure the instance template

An instance template is an API resource that you can use to create VM instances and managed instance groups. Instance templates define the machine type, boot disk image, subnet, labels, and other instance properties.

  1. In the Cloud Console, in the Navigation menu (Navigation menu icon), select Compute Engine > Instance templates.

  2. Click Create instance template.

  3. For Name, type template-1.

  4. Choose Region :

  5. Click Advanced Options.

  6. Click Management.

  7. Under Metadata, click + ADD ITEM and specify the following:

    Key Value
    startup-script-url gs://cloud-training/gcpnet/httplb/startup.sh
Note: The startup-script-url specifies a script that will be executed 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. You can find out more about this script by referring to the script reference guide.
  1. Click Networking.

  2. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Network tags allow-health-checks
    Network interface > Network default
    Subnetwork default ()
    External IPv4 address None
  3. Click DONE.

Note: The network tag allow-health-checks ensures that the Health Check firewall rule applies to these instances.
  1. Click Create. Wait for the instance template to be created.

  2. Now, prepare to create another instance template by copying template-1. Click the template-1. Information about the template-1 appears.

  3. Near the top of the page, click CREATE SIMILAR.

  4. For Name, type template-2.

  5. Choose Region :

  6. Click Advanced Options.

  7. Click Networking > Network interface.

  8. Select default as the Subnetwork, and click DONE.

  9. Click Create.

Create the managed instance groups

Create a managed instance group in and one in .

  1. In the Navigation menu, select Compute Engine > Instance groups.

  2. Click Create Instance group.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Name mig-1
    Instance template template-1
    Location Multiple zones
    Region
    Autoscaling > Minimum number of instances 1
    Autoscaling > Maximum number of instances 5
    Autoscaling > Autoscaling signals Click CPU utilization, set Target CPU utilization 80
    Initialization period 45
Note: 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.
  1. Click Create.

    Repeat the same procedure for mig-2 in .

  2. Click Create Instance group.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Name mig-2
    Location Multiple zones
    Region
    Instance template template-2
    Autoscaling > Minimum number of instances 1
    Autoscaling > Maximum number of instances 5
    Autoscaling > Autoscaling signals Click CPU utilization, set Target CPU utilization 80
    Initialization period 45
  4. Click Create.

Click Check my progress to verify the objective. Configure instance templates and create instance groups

Verify the backends

Verify that VM instances are being created in both regions and access their HTTP sites.

  1. In the Navigation menu, click Compute Engine > VM instances.
    Notice the instances that start with mig-1 and mig-2.

    These instances are part of the managed instance groups.

  2. In Cloud Console, note the name and the zone of the VM instance located in region. (You will need to use these values in a moment.)

  3. On the Google Cloud Platform menu, click Activate Cloud Shell (Activate Cloud Shell icon) to open Cloud Shell. If prompted, click Continue.

  4. In Cloud Shell, execute this command to execute SSH commands in the VM instance located in region:

gcloud compute ssh <INSTANCE_NAME> --zone <ZONE>
  1. If prompted, click Authorize.
  2. When asked if you want to continue, enter Y.
  3. When prompted for a passphrase, press Enter or Return. This will generate an empty passphrase.
  4. To confirm the empty passphrase, press Enter or Return again. After a moment, Cloud Shell uses IAP tunneling to make an SSH connection to the VM instance in . The Cloud Shell command line can now be used as the VM instance's command line.
  5. At the command line, enter the following:
curl localhost

You should see the Apache welcome page, which was installed as part of the startup-script-url script that changes the welcome page to include the client IP and the name, region, and zone of the VM instance.

  1. Copy the internal IP address of an instance located in the region.
  2. Test the connection by running the following command:
curl $IP_Address Note: Replace the value $IP_Address with the internal IP of the instance.
  1. Enter exit to close the SSH session.

Task 4. Configure the HTTP load balancer

Next, you will configure the HTTP load balancer to balance traffic between the two backends (mig-1 in and mig-2 in ), as illustrated in the network diagram.

Network diagram of an HTTP load balancer with global backends

Start the configuration

  1. In the Navigation menu (Navigation menu icon) click View All Products and navigate to Network services > Load balancing.
  2. Click Create load balancer.
  3. Under Type of load balancer, select Application Load Balancer (HTTP/HTTPS), click Next.
  4. Under Public facing or internal, select Public facing (external) and click Next.
  5. Under Global or single region deployment, select Best for global workloads, click Next.
  6. Under Load balancer generation, select Classic Application Load Balancer, click Next.
  7. Click Configure.
  8. For Load Balancer Name, type http-lb.

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.

  1. Click Backend configuration.

  2. For Backend services & backend buckets, click Create a backend service.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (select option as specified)
    Name http-backend
    Backend type Instance group
    Backends > Instance group mig-1
    Port numbers 80
    Balancing mode Rate
    Maximum RPS 50
    Capacity 100
Note: This configuration means that the load balancer attempts to keep each instance of mig-1 at or below 50 requests per second (RPS).
  1. Click Done.

  2. Click Add backend.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (select option as specified)
    Instance group mig-2
    Port numbers 80
    Balancing mode Utilization
    Maximum backend utilization 80
    Capacity 100
Note: This configuration means that the load balancer attempts to keep each instance of mig-2 at or below 80% CPU utilization.
  1. Click Done.

  2. For Health Check, select Create a health check.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (select option as specified)
    Name http-health-check
    Protocol TCP
    Port 80
Note: Health checks determine which instances can receive new connections. This HTTP health check polls instances every 10 seconds, waits up to 5 seconds for a response, and treats 2 successful or 3 failed attempts as healthy or unhealthy, respectively.
  1. Click Create.
  2. Check the Enable Logging box.
  3. Set the Sample Rate to 1.
  4. Click Create.

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 direct static traffic to another backend. However, you are not configuring the host and path rules in this lab.

  1. Click Frontend configuration.

  2. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Protocol HTTP
    IP version IPv4
    IP address Ephemeral
    Port 80
  3. Click Done.

  4. Click Add Frontend IP and port.

  5. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Protocol HTTP
    IP version IPv6
    IP address Auto-allocate
    Port 80
  6. Click Done.

Note: HTTP(S) load balancing supports both IPv4 and IPv6 addresses for client traffic. Client IPv6 requests are terminated at the global load balancing layer and then proxied over IPv4 to your backends.

Review and create the HTTP load balancer

  1. Click Review and finalize.
  2. Review the Backend services and Frontend.
  3. Click Create.
    Wait for the load balancer to be created.
  4. Click on the name of the load balancer (http-lb).
  5. 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.
Note: The IPv6 address is the one in hexadecimal format.

Click Check my progress to verify the objective. Configure the HTTP load balancer

Task 5. Test the HTTP load balancer

Now that you have created the HTTP load balancer for your backends, it is time to verify that traffic is forwarded to the backend service.

Access the HTTP load balancer

  1. 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.
Note: It might take a couple of minutes to access the HTTP load balancer. In the meantime, you might get a 404 or 502 error. Keep trying until you see the page of one of the backends. Note: Depending on your proximity to and , you traffic is either forwarded to a mig-1 or mig-2 instance.
  1. 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

Next, you will create a new VM to simulate a load on the HTTP load balancer. Then you will determine whether traffic is balanced across both backends when the load is high.

  1. In the Cloud Console, in the Navigation menu (Navigation menu icon), select Compute Engine > VM instances.

  2. Click Create instance.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Name siege-vm
    Region
    Zone
  4. Click Create. Wait for the siege-vm instance to be created.

  5. At the Cloud Shell prompt, enter the following command to create an SSH connection to the siege-vm:

    gcloud compute ssh siege-vm --zone {{{project_0.default_zone_3|Zone 3}}}
  6. Run the following command to install siege:

sudo apt-get -y install siege
  1. 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:
export LB_IP=[LB_IP_v4]
  1. Verify it with echo:
echo $LB_IP
  1. To simulate a load, run the following command:
siege -c 250 http://$LB_IP
  1. In the Cloud Console, in the Navigation menu (Navigation menu icon) click View All Products and navigate to Network services > Load balancing.
  2. Click http-lb.
  3. Click Monitoring.
  4. Monitor the Frontend Location (Total inbound traffic) between North America and the two backends for 2 to 3 minutes.
  5. Return to the SSH terminal of siege-vm.
  6. Press CTRL+C to stop siege.

The output should look like this.

Output:

New configuration template added to /home/student-03-e8562fd77201/.siege Run siege -C to view the current settings in that file { "transactions": 26372, "availability": 100.00, "elapsed_time": 118.46, "data_transferred": 3.39, "response_time": 0.31, "transaction_rate": 222.62, "throughput": 0.03, "concurrency": 68.14, "successful_transactions": 1001, "failed_transactions": 0, "longest_transaction": 13.78, "shortest_transaction": 0.02 }

Task 6. Deny the siege-vm

You will now use Google Cloud Armor to deny the siege-vm from accessing the HTTP load balancer.

Create the security policy

Create a Google Cloud Armor security policy with a deny rule for the siege-vm.

  1. In the Cloud Console, in the Navigation menu, select Compute Engine > VM instances.
  2. Note the External IP of the siege-vm. This will be referred to as [SIEGE_IP].
Note: There are ways to identify the external IP address of a client trying to access your HTTP load balancer. For example, you could examine traffic captured by VPC Flow Logs in BigQuery to determine a high volume of incoming requests.
  1. In the Navigation menu (Navigation menu icon) click View All Products and navigate to Network Security > Cloud Armor > Cloud Armor policies.

  2. Click Create policy.

  3. Specify the following, and leave the remaining settings as their defaults:

    Property Value (type value or select option as specified)
    Name deny-siege
    Default rule action Allow
  4. Click Next step.

  5. Click Add rule.

  6. Specify the following, and leave the remaining settings as 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
  7. Click Save change to rule.

  8. Click Next step.

  9. Click Add Target.

  10. For Type, select Backend service (external application load balancer).

  11. For Target, select http-backend and if prompted confirm Replace.

  12. Click Create policy.
    Wait for the policy to be created before moving to the next step.

Note: Alternatively, you could set the default rule to Deny and only allow traffic from authorized users/IP addresses.

Click Check my progress to verify the objective. Deny the siege-vm

Verify the security policy

Next, you will verify that the siege-vm cannot access the HTTP load balancer.

  1. Return to the SSH terminal of siege-vm.
  2. To access the load balancer, run the following:
curl http://$LB_IP

The output should look like this.

Output:

<!doctype html><meta charset="utf-8"><meta name=viewport content="width=device-width, initial-scale=1"><title>403</ title>403 Forbidden Note: It might take a couple of minutes for the security policy to take affect. If you are able to access the backends, keep trying until you get the 403 Forbidden error.
  1. 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.
Note: You can access the HTTP load balancer from your browser because of the default rule to allow traffic; however, you cannot access it from the siege-vm because of the deny rule that you implemented.
  1. To simulate a load, run the following command:
siege -c 250 http://$LB_IP

The command will not generate any output.

Explore the security policy logs to determine whether this traffic is also blocked.

  1. In the Navigation menu (Navigation menu icon) click View All Products and navigate to Network Security > Cloud Armor > Cloud Armor policies.
  2. Click deny-siege.
  3. Click Logs.
  4. Click View policy logs. Logs Explorer is launched. You should see the logs for the http-lb load balancer.
  5. Expand a log entry in Query results.
  6. Expand httpRequest.

The request should be from the siege-vm IP address. If not, expand another log entry.

  1. Expand jsonPayload.
  2. Expand enforcedSecurityPolicy.
    Notice that the configuredAction is to DENY with the name deny-siege.
Note: Google 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!

In this lab, you have configured an HTTP load balancer with backends in and . Then you stress-tested the load balancer with a VM and denied the IP address of that VM with Google Cloud Armor. In addition, you were able to explore the security policy logs to identify why the traffic was blocked.

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 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.

시작하기 전에

  1. 실습에서는 정해진 기간 동안 Google Cloud 프로젝트와 리소스를 만듭니다.
  2. 실습에는 시간 제한이 있으며 일시중지 기능이 없습니다. 실습을 종료하면 처음부터 다시 시작해야 합니다.
  3. 화면 왼쪽 상단에서 실습 시작을 클릭하여 시작합니다.

시크릿 브라우징 사용

  1. 실습에 입력한 사용자 이름비밀번호를 복사합니다.
  2. 비공개 모드에서 콘솔 열기를 클릭합니다.

콘솔에 로그인

    실습 사용자 인증 정보를 사용하여
  1. 로그인합니다. 다른 사용자 인증 정보를 사용하면 오류가 발생하거나 요금이 부과될 수 있습니다.
  2. 약관에 동의하고 리소스 복구 페이지를 건너뜁니다.
  3. 실습을 완료했거나 다시 시작하려고 하는 경우가 아니면 실습 종료를 클릭하지 마세요. 이 버튼을 클릭하면 작업 내용이 지워지고 프로젝트가 삭제됩니다.

현재 이 콘텐츠를 이용할 수 없습니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

감사합니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

한 번에 실습 1개만 가능

모든 기존 실습을 종료하고 이 실습을 시작할지 확인하세요.

시크릿 브라우징을 사용하여 실습 실행하기

이 실습을 실행하려면 시크릿 모드 또는 시크릿 브라우저 창을 사용하세요. 개인 계정과 학생 계정 간의 충돌로 개인 계정에 추가 요금이 발생하는 일을 방지해 줍니다.