Ends in
00
days
00
hrs
00
mins
00
secs
SHOP NOW

🚀 Get 20% OFF All Azure Products Today — Azure Super Sale!

Back to Course

GCP PlayCloud Labs

0% Complete
0/0 Steps
  1. GCP PlayCloud Labs
  2. Guided Lab: How to Launch a GCP Compute Engine Linux Instance
  3. Guided Lab: Creating a VM Using Instance Templates
  4. Guided Lab: Creating and Managing Instance Groups in Compute Engine
  5. Guided Lab: Creating a Spot VM Instance
  6. Guided Lab: Configuring Shielded VM Options
  7. Guided Lab: Exploring Instance Metadata in Google Cloud
  8. Guided Lab: Vertically Scaling a VM Instance
  9. Guided Lab: Setting up a Web Server on a VM Instance
  10. Guided Lab: Using Startup Scripts in GCP VM Instances
  11. Guided Lab: Creating a Custom Image from a VM Instance with Web Server in Google Cloud
  12. Guided Lab: Creating VM Snapshots and Restoring a VM from a Snapshot
  13. Guided Lab: Setting Up and Managing a Database on a VM Instance
  14. Guided Lab: Installing WordPress on an Ubuntu VM Instance with LEMP Stack
  15. Guided Lab: Deploying a LAMP Stack on a Compute Engine VM
  16. Guided Lab: Reserving or Promoting a Static IP Address for a VM Instance
  17. Guided Lab: SSH Access to GCP VM Instance from Local Machine using SSH Key Pair
  18. Guided Lab: Guarding Your VM with Deletion Protection
  19. Guided Lab: Setting Up a Linux Bastion Host on GCP
  20. Guided Lab: Creating a Cloud Storage Bucket
  21. Guided Lab: Uploading, Organizing, and Managing Objects in Cloud Storage
  22. Guided Lab: Exploring Google Cloud Storage Classes
  23. Guided Lab: Hosting a Static Website in Google Cloud Storage Bucket
  24. Guided Lab: Protecting Data on Cloud Storage Bucket Against Accidental Delete and Overwrite Using Object Versioning
  25. Guided Lab: Using Cloud Storage Lifecycle Rules to Automate Object Management
  26. Guided Lab: Managing Cloud Storage Buckets via SSH Commands
  27. Guided Lab: Creating a Cloud SQL Instance
  28. Guided Lab: Running SQL Commands in Cloud SQL Studio
  29. Guided Lab: Creating and Restoring Cloud SQL Backups
  30. Guided Lab: Integrating Cloud SQL Database instance with a VM instance
  31. Guided Lab: Connecting Cloud SQL Database with MySQL Workbench (Local)
  32. Guided Lab: Guarding Your Cloud SQL Instances with Deletion Protection
  33. Guided Lab: Creating a Cloud NAT Gateway
  34. Guided Lab: Creating a Google Kubernetes Engine (GKE) Cluster
  35. Guided Lab: Connecting to a Kubernetes Engine Cluster
  36. Guided Lab: Deploying a Simple Web Application on GKE
  37. Guided Lab: Creating a Custom Virtual Private Cloud (VPC)
  38. Guided Lab: Establishing VPC Peering for Secure Cross‑Network Communication
  39. Guided Lab: Configuring Firewall Rules to Secure and Access a VM
  40. Guided Lab: Creating an Application Load Balancer
  41. Guided Lab: Creating a Network Load Balancer
Lesson 40 of 41
In Progress

Guided Lab: Creating an Application Load Balancer

Description

An Application Load Balancer (ALB) in Google Cloud Platform (GCP) intelligently distributes HTTP(S) traffic across multiple backend instances, ensuring high availability, scalability, and fault tolerance for your applications.

In this guided lab, you will build a global external HTTP load balancer that routes traffic between two VM instances running Nginx web servers. By the end, you’ll see how GCP’s load balancing service automatically balances requests and maintains service reliability.

Prerequisites

To ensure the successful completion of this lab, we highly recommend taking the following guided labs to gain the necessary understanding:

Objectives

In this lab, you will:

  • Launch two Compute Engine VM instances with Nginx installed via startup scripts.
  • Serve unique custom HTML pages from each VM.
  • Group the VMs into an Unmanaged Instance Group.
  • Configure a global external HTTP load balancer with a frontend and backend service.
  • Create and apply an HTTP health check to monitor backend availability.
  • Verify that traffic alternates between the two web servers when accessing the load balancer’s IP.

Lab Steps

Create a Compute Engine VM Instance

1. Navigate to Compute Engine → VM instances → Create Instance.

2. Configure:

  • Name: webserver-1 and webserver-2
  • Machine type: e2-micro
  • Boot disk: Ubuntu 24.04 LTS Minimal (x86/64, amd64 noble minimal image built on 2025‑12‑17)
  • Firewall: Check Allow HTTP traffic

3. Navigate to the Advanced section.

4. Add a startup script to install Nginx and serve a unique page:

# Update system
sudo apt update -y

# Install Nginx
sudo apt install nginx -y

# Start Nginx
sudo systemctl start nginx

# Create a custom HTML page in the HTML directory
echo '<h1>Hello from Webserver-1</h1>' | sudo tee /usr/share/nginx/html/mypage.html > /dev/null

# Add the configuration directly
echo 'server {
    listen 80 default_server;
    server_name _;
    root /usr/share/nginx/html;
    
    location / {
        index mypage.html;
    }
}' | sudo tee /etc/nginx/conf.d/server.conf > /dev/null

# Remove the default site to avoid duplicate default_server errors:
sudo unlink /etc/nginx/sites-enabled/default

# Test and Reload Nginx for the changes to take effect
sudo nginx -t && sudo service nginx reload

# Enable Nginx at boot
sudo systemctl enable nginx

(Change the message for webserver-2 to “Hello from Webserver-2”)

5. Once done, click the Create button.

Wait for the VMs to finish provisioning.

Verify the Setup

1. Once the VM is running, copy its External IP address.

2. Open a browser and navigate to http://<EXTERNAL_IP>.

3. You should see the custom page: “Hello from Webserver-1” and “Hello from Webserver-2

If the page does not load:

  • Try refreshing the browser multiple times — the startup script is still running in the background and may take a moment to complete.
  • Ensure the firewall rule Allow HTTP traffic is enabled.
  • SSH into the VM and run: systemctl status nginx to confirm Nginx is running.
Create an Unmanaged Instance Group

1. Go to Compute Engine → Instance groups → Create Instance Group.

2. Select Unmanaged instance group.

3. Name the group (e.g., instance-group-1).

4. Under Location, change the Zone to us-central1-c

5. Add both VM instances (webserver-1 and webserver-2) to the group.

6. Click the Create button.

Create the Load Balancer

1. Navigate to Network services → Load balancing → Create Load Balancer.

2. Choose HTTP(S) Load Balancing → Click Next → Leave other configurations at their default values → Start configuration.

Configure the Frontend and the Backend

1. Frontend configuration:

  • Protocol: HTTP
  • IP: Create a new static IP (recommended).
  • Port: 80

2. Backend configuration:

  • Backend type: Instance group
  • Health check: Create a new HTTP health check (port 80).
  • Select the unmanaged instance group (instance-group-1).
  • Port numbers: 80
  • Disable the CDN.
Review and Create

1. Review the configuration summary.

2. Add the desired Load Balancer name:

3. Click Create to provision the load balancer.

Verify the Load Balancer

1. Once provisioning completes, copy the frontend IP address.

2. Open a browser and navigate to http://<LOAD_BALANCER_IP>.

3. Refresh several times—you should see responses alternating between:

  • Hello from Webserver-1
  • Hello from Webserver-2

Congratulations! You have successfully created an Application Load Balancer in GCP using an Unmanaged Instance Group. This setup ensures high availability and scalability by distributing traffic across multiple VM instances. You also learned how to verify backend health and confirm traffic distribution.

Skip to content