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 41 of 41
In Progress

Guided Lab: Creating a Network Load Balancer

Description

A Network Load Balancer (NLB) in Google Cloud Platform (GCP) distributes TCP/UDP traffic across backend instances at Layer 4 (transport layer). Unlike the Application Load Balancer, which operates at Layer 7 (HTTP/HTTPS), the NLB provides low-latency, pass-through load balancing for applications such as gaming servers, databases, or custom TCP/UDP services.

In this guided lab, you will configure a regional external TCP load balancer that balances traffic between two VM instances running simple TCP echo servers on port 9000. By the end, you’ll understand how GCP’s NLB ensures scalability and fault tolerance for non-HTTP workloads

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 VM instances running a TCP echo service on port 9000.
  • Create a firewall rule to allow TCP traffic on port 9000.
  • Group the VMs into an Unmanaged Instance Group.
  • Configure a regional external TCP load balancer.
  • Create and apply a TCP health check.
  • Verify that traffic is distributed between the backend servers

Lab Steps

Create a Compute Engine VM Instance

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

2. Configure:

  • Name: tcp-server-1 and tcp-server-2
  • Machine type: e2-micro
  • Boot disk: Ubuntu 24.04 LTS Minimal (x86/64, amd64 noble minimal image built on 2025‑12‑17)
  • Firewall: Leave default (we’ll add a custom rule later)

3. Navigate to the Advanced section.

4. In the Startup script field, paste the following:

#!/bin/bash
sudo apt update -y
sudo apt install -y netcat-openbsd

# Create the echo server script
cat << 'EOF' > /home/tcpecho.sh
#!/bin/bash
nohup nc -lk 9000 > /tmp/nc_input &
tail -f /tmp/nc_input | while read line; do
  echo "Hello from $(hostname): $line"
done
EOF

5. Once done, click the Create button.

Wait for the VMs to finish provisioning.

Create Firewall Rule for Port 9000

1. Navigate to VPC network → Select the Default VPC.

2. Navigate to Firewalls → Create VPC firewall rule → Configure:

  • Name: allow-tcp-rule
  • Direction of traffic: Ingress
  • Targets: All instances in the network
  • Source filter: IP ranges → 0.0.0.0/0
  • Protocols and ports: TCP → 9000

3. Click Create.

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 based on the zone of the created VMs.

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

6. Click the Create button.

Create the Network Load Balancer

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

2. Choose Network Load Balancer → Next → Leave other configurations at their default values → Start configuration.

Backend Configuration

  • Backend type: Instance group
  • Health check: Create a new TCP health check (port 9000)
  • Named port: tcp9000
  • Instance group: Select the created instance group (instance-group-1)

Frontend Configuration

  • Protocol: TCP
  • IP: Create a new static IP (recommended)
  • Port: 9000
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 Network Load Balancer

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

2. Connect to the two servers via SSH, then run the shell script.

sudo bash /home/tcpecho.sh

3. Open the terminal on your local machine.

4. Run the following loop to generate multiple connections:

Windows:

1..20 | ForEach-Object { "test $_" | ncat <LOAD_BALANCER_IP> 9000 }

macOS/ Linux:

for i in {1..20}; do
  echo "test $i" | ncat <LOAD_BALANCER_IP> 9000
done

5. Expected output (alternating between servers):

Congratulations! You have successfully created a Network Load Balancer in GCP using an Unmanaged Instance Group. This setup demonstrates how GCP distributes TCP traffic at Layer 4, ensuring scalability and reliability. You also learned how to configure firewall rules, health checks, and confirm traffic distribution with a clear echo verification loop across Windows, macOS, and Linux using ncat.

Skip to content