Every website or application eventually hits the same problem. One server cannot handle all the traffic, and if that one server fails, everything goes down with it. A load balancer solves both problems. It sits in front of several identical servers, shares incoming requests between them, and quietly stops sending traffic to any server that stops responding.
Google Cloud gives you a managed load balancer that does this without you running any load balancing software. You create the pieces in the console: a group of virtual machines, a health check that decides which machines are healthy, a backend service that points at the group, and a frontend that gives users one address to visit. Google then spreads the traffic for you and scales the load balancer itself as demand grows.
In this guide you will build a complete HTTP load balancer from scratch. We begin with when load balancing is the right tool and which type to choose. Then we build an instance group with a template and a startup script that installs the Apache web server, set up autoscaling, open the firewall, and create the load balancer with its backend, health check and frontend. Every original screenshot stays in place. At the end you will find a short section on load balancing inside Google Kubernetes Engine, plus common mistakes, a short FAQ and how to clean up.
Reach for a load balancer when any of these are true:
Google Cloud offers several load balancer types. The right one depends on the traffic you carry and who sends it.
| Type | Works with | Use it for |
|---|---|---|
| Application Load Balancer | HTTP and HTTPS traffic | Websites and web applications, the type built in this guide |
| Proxy Network Load Balancer | TCP traffic with a proxy | Non HTTP services that need global reach or SSL offload |
| Passthrough Network Load Balancer | TCP, UDP and other protocols, regional | Services that need the client IP kept or non web protocols |
| Internal load balancers | Traffic inside your VPC network | Private services that only other systems call |
The console names for these types have changed over the years, so confirm the exact labels in your project. This guide builds an external HTTP load balancer, which is the usual choice for a public website.
Prerequisites:
An instance group is the set of identical virtual machines that will sit behind the load balancer. A managed instance group creates them from a template, which is what lets Google add and remove machines automatically.

Click on Create Instance Group

Give a name for instance group.
Select the Region and Zone

The template is the blueprint every machine in the group is built from.

Give a new Instance Template.
Choose the Specification for instance template.

In firewall, Tick Allow.
Click Management, security, disks, networking, sole tenancy

Under the Management section, paste a startup script. It runs when each machine boots and installs the Apache web server, so every machine in the group serves a web page without you logging in to any of them.
#! /bin/bash
apt-get update
apt-get install apache2 -y

Tip: make each machine show its own name on the default page, so you can see the load balancer sharing requests. Add this line after the install line:
echo “Served by $(hostname)” > /var/www/html/index.html

Then Click Save and Continue

Autoscaling lets the group add machines when they are busy and remove them when they are idle. That keeps cost down and capacity up.

Give the metric type as CPU Utilization and give the target percentage.
Click Done.

Give the minimum and maximum number of instances. In autohealiing, Give No health Check.
Then Click Create.

The load balancer finds the right port on your machines through a named port. You attach the name http to port 80 on the instance group.

Edit.

Click on Specify port name mapping.

Click on Add item.

Give the port name as http and port number as 80.

Save.

A firewall rule lets web traffic and the health check probes reach your machines.

on create Firewall.

Give the name for firewall

the target tags.
Give the Source IP ranges
Select the tcp and give port number as 80

A static address gives your load balancer a front door that never changes. Reserve one in the console under VPC network and then IP addresses.

In the Type, Click on Ephemeral.

Change it into static.

Give the name for static and Click reserve.

Click on network services > Load balancing

Check: reserve this address as its own resource, not by converting a virtual machine address, and select it later in the frontend configuration. Converting a machine address would keep the machine address, not the load balancer address.

In HTTP load balancing, Click on Start configuration

Select From internet to my VM’s and Click Continue.

In the Backend Configuration. Select Backend Services > Create a backend service.

The health check is how the load balancer knows which machines are working. It sends a small request to each one and stops sending traffic to any that fail to answer.

Select the created Instance Group. Give the port number as 80.
Click Done.


Then Click Create

After a few minutes the load balancer appears in the list. Open the load balancer and look at its backend. When every machine shows as healthy, paste the load balancer address into a browser. If you used the hostname tip from Step 3, refresh several times and watch the page change between machines.

Give Load name for load balancing. Click Create.

The Load balancer will be created

A new load balancer can take several minutes to start answering, so give it a little time before you assume something is wrong.
Because this page lives in the Kubernetes section, here is how the same idea works in GKE. You do not click through the console. You describe what you want in Kubernetes and GKE builds the load balancer for you.
A minimal Service looks like this:
apiVersion: v1
kind: Service
metadata:
name: hello-lb
spec:
type: LoadBalancer
selector:
app: hello
ports:
– port: 80
targetPort: 8080
Apply it and wait for the external address:
kubectl apply -f service.yaml
kubectl get service hello-lb –watch
Two settings are worth knowing. The Local value of externalTrafficPolicy keeps the real client IP address and sends traffic only to nodes that have a ready Pod. The Cluster value spreads traffic more evenly but hides the client address. For a private service, an annotation turns the Service into an internal load balancer.
You have now built a working HTTP load balancer with health checks and autoscaling. From here, try adding HTTPS with a certificate or put the same backend behind a GKE Ingress and compare how each feels to operate.