GCP - Application Load Balancing
This guide provides a beginner-friendly walkthrough for setting up a Global External Application Load Balancer (HTTP/HTTPS) on Google Cloud Platform to distribute traffic across a set of virtual machines.
Phase 1: Prepare Your Backend (Instance Groups)
Before balancing traffic, you must define the servers that will handle the requests.
- Create an Instance Template:
Go to Compute Engine > Instance templates. Define your machine type and ensure you check Allow HTTP traffic. In the networking tags, add
allow-health-check.
- Create a Managed Instance Group (MIG):
Go to Instance groups and create a new group. Link it to your template. Set your autoscaling policy (e.g., minimum 2 instances) to ensure high availability.
Phase 2: Configure the Load Balancer
This stage connects the internet-facing IP address to your backend servers.
- Initialize: Navigate to Network services > Load balancing. Select Create Load Balancer and choose the Application Load Balancer (HTTP/HTTPS).
- Backend Configuration:
Create a Backend Service. Select your Instance Group as the backend.
Crucial: Create a Health Check (Protocol: HTTP, Port: 80). This allows GCP to stop sending traffic to any server that crashes.
- Frontend Configuration:
Specify the protocol (HTTP or HTTPS). Reserve a Static IP Address rather than using an Ephemeral one so your website's address doesn't change unexpectedly.
Phase 3: Firewall Rules & Verification
Traffic must be allowed to flow from the Google Cloud Load Balancer to your instances.
- Allow Health Checks: In VPC Network > Firewall, create a rule allowing
tcp:80 from the source ranges 130.211.0.0/22 and 35.191.0.0/16.
- Final Test: Copy the Frontend IP from your Load Balancer dashboard. Paste it into a browser. It may take several minutes for the initial health checks to pass before the page loads.