arrow_back

Create an Internal Load Balancer

Join Sign in

Create an Internal Load Balancer

50 minutes 5 Credits

GSP216

Google Cloud Self-Paced Labs

Overview

Google Cloud offers Internal Load Balancing for your TCP/UDP-based traffic. Internal Load Balancing enables you to run and scale your services behind a private load balancing IP address that is accessible only to your internal virtual machine instances.

In this lab you create two managed instance groups in the same region. Then, you configure and test an Internal Load Balancer with the instances groups as the backends, as shown in this network diagram:

Network_Diagram.png

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 and test an internal 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.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Chrome OS device, open an Incognito window to run this lab.

How to start your lab and sign in to the Google Cloud Console

  1. 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 a panel populated with the temporary credentials that you must use for this lab.

    Open Google Console

  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Sign in

    Tip: Open the tabs in separate windows, side-by-side.

  3. In the Sign in page, paste the username that you copied from the left panel. Then copy and paste the password.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Training credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).

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

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.

Explore the my-internal-app network

The network my-internal-app with subnet-a and subnet-b along with firewall rules for RDP, SSH, and ICMP traffic have been configured for you.

  1. In the Console, navigate to Navigation menu > VPC network > VPC networks.

nav_vpc.png

  1. Scroll down and notice the my-internal-app network with its subnets: subnet-a and subnet-b

    Each Google Cloud project starts with the default network. In addition, the my-internal-app network has been created for you, as part of your network diagram.

    You will create the managed instance groups in subnet-a and subnet-b. Both subnets are in the us-central1 region because an Internal Load Balancer is a regional service. The managed instance groups will be in different zones, making your service immune to zonal failures.

Create the HTTP firewall rule

Create a firewall rule to allow HTTP traffic to the backends from the Load Balancer and the internet (to install Apache on the backends).

  1. Still in VPC network, in the left pane click Firewall.

left-pane.png

  1. Notice the app-allow-icmp and app-allow-ssh-rdp firewall rules.

    These firewall rules have been created for you.

  2. Click Create Firewall Rule.

  3. Set the following values, leave all other values at their defaults:

    Property Value (type value or select option as specified)
    Name app-allow-http
    Network my-internal-app
    Targets Specified target tags
    Target tags lb-backend
    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
  1. Click Create.

Create the health check firewall rules

Health checks determine which instances of a Load Balancer can receive new connections. For Internal 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 rules 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 app-allow-health-check
    Targets Specified target tags
    Target tags lb-backend
    Source filter IPv4 Ranges
    Source IPv4 ranges 130.211.0.0/22 and 35.191.0.0/16
    Protocols and ports Specified protocols and ports, and then check tcp
  1. Click Create.

Click Check my progress to verify the objective.

Configure HTTP and health check firewall rules

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 Internal Load Balancer.

Configure the instance templates

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. Create an instance template for both subnets of the my-internal-app network.

  1. In the Console, navigate to Navigation menu > Compute Engine > Instance templates.
  2. Click Create instance template.
  3. For Name, type instance-template-1.
  4. For Series, select N1.
  5. Click Networking, disks, security, management, sole tenancy.

advance-options.png

  1. Click Networking.

  2. For Network tags, specify lb-backend.

  3. For Network interfaces, click the dropdown icon to edit.

  4. Set the following values, leave all other values at their defaults:

    Property Value (type value or select option as specified)
    Network my-internal-app
    Subnetwork subnet-a
  5. Click Done.

  6. Click Management.

  7. Under Metadata, click Add item and specify the following:

    Key Value
    startup-script-url gs://cloud-training/gcpnet/ilb/startup.sh
  1. Click Create.

  2. Wait for the instance template to be created.

Configure the next instance template

Create another instance template for subnet-b by copying instance-template-1:

  1. Still in Instance templates, check the box next to instance-template-1, then click Copy. You will see the instance is named instance-template-2.

  2. Click Networking, disks, security, management, sole tenancy.

  3. Click the Networking tab.

  4. For Network interfaces, click the dropdown icon to edit.

  5. Select subnet-b as the Subnetwork.

  6. Click Done and then click Create.

Create the managed instance groups

Create a managed instance group in subnet-a (us-central1-a) and one subnet-b (us-central1-b).

  1. Still in Compute Engine, in the left pane click Instance groups, and then click Create Instance group.

  2. Set the following values, leave all other values at their defaults:

    Property Value (type value or select option as specified)
    Name instance-group-1
    Instance template instance-template-1
    Location Single-zone
    Region us-central1
    Zone us-central1-a
    Autoscaling > Minimum number of instances 1
    Autoscaling > Maximum number of instances 5
    Autoscaling > Autoscaling metrics (click the dropdown icon to edit) > Metric type CPU utilization
    Target CPU utilization 80
    Cool-down period 45
  1. Click Create.

    Repeat the same procedure for instance-group-2 in us-central1-b:

  2. Click Create Instance group.

  3. Set the following values, leave all other values at their defaults:

    Property Value (type value or select option as specified)
    Name instance-group-2
    Instance template instance-template-2
    Location Single-zone
    Region us-central1
    Zone us-central1-b
    Autoscaling > Minimum number of instances 1
    Autoscaling > Maximum number of instances 5
    Autoscaling > Autoscaling metrics (click the dropdown icon to edit) > Metric type CPU utilization
    Target CPU utilization 80
    Cool-down period 45
  4. Click Create.

Verify the backends

Verify that VM instances are being created in both subnets and create a utility VM to access the backends' HTTP sites.

  1. Still in Compute Engine, click VM instances.

  2. Notice two instances that start with instance-group-1 and instance-group-2.

    These instances are in separate zones and their internal IP addresses are part of the subnet-a and subnet-b CIDR blocks.

  3. Click Create instance.

  4. Set the following values, leave all other values at their defaults:

    Property Value (type value or select option as specified)
    Name utility-vm
    Region us-central1
    Zone us-central1-f
    Series N1
    Machine type f1-micro (1 shared vCPU)
  5. Click Networking, disks, security, management, sole tenancy.

  6. Click Networking.

  7. For Network interfaces, click the dropdown icon to edit.

  8. Set the following values, leave all other values at their defaults:

    Property Value (type value or select option as specified)
    Network my-internal-app
    Subnetwork subnet-a
    Primary internal IP Ephemeral (Custom)
    Custom ephemeral IP address 10.10.20.50
  9. Click Done and then click Create.

network_interface.png

Click Check my progress to verify the objective.

Configure instance templates and create instance groups
  1. Note that the internal IP addresses for the backends are 10.10.20.2 and 10.10.30.2.
  1. For utility-vm, click SSH to launch a terminal and connect.

  2. To verify the welcome page for instance-group-1-xxxx, run the following command:

curl 10.10.20.2

The output should look like this (do not copy; this is example output):

<h1>Internal Load Balancing Lab</h1><h2>Client IP</h2>Your IP address : 10.10.20.50<h2>Hostname</h2>Server Hostname: instance-group-1-1zn8<h2>Server Location</h2>Region and Zone: us-central1-a
  1. To verify the welcome page for instance-group-2-xxxx, run the following command:

curl 10.10.30.2

The output should look like this (example output):

<h1>Internal Load Balancing Lab</h1><h2>Client IP</h2>Your IP address : 10.10.20.50<h2>Hostname</h2>Server Hostname: instance-group-2-q5wp<h2>Server Location</h2>Region and Zone: us-central1-b

  1. Close the SSH terminal to utility-vm:

exit

Configure the Internal Load Balancer

Configure the Internal Load Balancer to balance traffic between the two backends (instance-group-1 in us-central1-a and instance-group-2 in us-central1-b), as illustrated in this diagram:

Network_Diagram.png

Start the configuration

  1. In the Cloud Console, navigate to Navigation menu > Network Services > Load balancing, and then click Create load balancer.
  2. Under TCP Load Balancing, click on Start configuration.
  3. For Internet facing or internal only, select Only between my VMs.
  1. Click Continue.

  2. For Name, type my-ilb.

  3. For Region, select us-central1.

  4. For Network, select my-internal-app.

Configure the regional backend service

The backend service monitors instance groups and prevents them from exceeding configured usage.

  1. Click on Backend configuration.

  2. Set the following values, leave all other values at their defaults:

    Property Value (select option as specified)
    Instance group instance-group-1 (us-central1-a)
  3. Click Add backend.

  4. For Instance group, select instance-group-2 (us-central1-b).

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

  6. Set the following values, leave all other values at their defaults:

    Property Value (select option as specified)
    Name my-ilb-health-check
    Protocol TCP
    Port 80
  1. Click Save.

  2. Click Done.

  3. Verify that there is a blue check mark next to Backend configuration in the Cloud Console. If not, double-check that you have completed all the steps above.

Configure the frontend

The frontend forwards traffic to the backend.

  1. Click on Frontend configuration.

  2. Specify the following, leaving all other values with their defaults:

    Property Value (type value or select option as specified)
    Subnetwork subnet-b
    Internal IP Under IP address select Create IP address
  3. Specify the following, leaving all other values with their defaults:

    Property Value (type value or select option as specified)
    Name my-ilb-ip
    Static IP address Let me choose
    Custom IP address 10.10.30.5
  4. Click Reserve.

  5. In Port number, type 80.

  6. Click Done .

Review and create the Internal Load Balancer

  1. Click on Review and finalize.
  2. Review the Backend and Frontend.

review_and_finalize.png

  1. Click on Create. Wait for the Load Balancer to be created, before moving to the next task.

Click Check my progress to verify the objective.

Configure the Internal Load Balancer

Test the Internal Load Balancer

Verify that the my-ilb IP address forwards traffic to instance-group-1 in us-central1-a and instance-group-2 in us-central1-b.

Access the Internal Load Balancer

  1. In the Cloud Console, navigate to Navigation menu > Compute Engine > VM instances.

  2. For utility-vm, click SSH to launch a terminal and connect.

  3. To verify that the Internal Load Balancer forwards traffic, run the following command:

curl 10.10.30.5

The output should look like this (example output):

<h1>Internal Load Balancing Lab</h1><h2>Client IP</h2>Your IP address : 10.10.20.50<h2>Hostname</h2>Server Hostname: instance-group-1-1zn8<h2>Server Location</h2>Region and Zone: us-central1-a
  1. Run the same command a couple more times.

You should be able to see responses from instance-group-1 in us-central1-a and instance-group-2 in us-central1-b.

2_groups.png

Congratulations!

In this lab you created two managed instance groups in the us-central1 region, along with firewall rules to allow HTTP traffic to those instances and TCP traffic from the Google Cloud health checker. Then, you configured and tested an Internal Load Balancer for those instance groups.

completion_Networking_in_Google_Cloud

Finish Your Quest

This self-paced lab is part of the Quest, Networking in the Google Cloud. A Quest is a series of related labs that form a learning path. Completing this Quest earns you the badge above 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 and get immediate completion credit if you've taken this lab. See other available Quests.

Take Your Next Lab

Continue your Quest with Dynamic VPN Gateways - Cloud Routers.

Next Steps / Learn More

For information on the basic concepts of Load Balancing, see Google Cloud Load Balancing Documentation.

Manual Last Updated March 11, 2022
Lab Last Tested March 11, 2022

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.