When your application outgrows a single virtual machine, you need a way to distribute traffic across several instances, terminate TLS in one place, and route requests based on URL, host, or path. The google cloud load balancer service does all of this as a fully managed, globally distributed frontend, so you do not have to run and patch your own proxy fleet. In this guide, you will build an external HTTPS load balancer that routes traffic to a managed instance group, with a valid TLS certificate and a health check that keeps unhealthy instances out of rotation.

By the end, you will have a single anycast IP address serving HTTPS traffic, with HTTP automatically redirected to HTTPS, and a clear understanding of how each component fits together.
How the Google Cloud Load Balancer Works
Unlike a traditional load balancer that lives in one region, the google cloud load balancer is built on Google’s global edge network. A single anycast IP address accepts traffic from users anywhere in the world and routes it to the nearest healthy backend. The main components are:
- Frontend: The external IP address, forwarding rule, and target proxy that accept incoming traffic on ports 80 and 443.
- URL map: The routing rules that send requests to different backends based on host or path, for example sending
/api/to one backend and everything else to another. - Backend service: The configuration that connects a set of backends, defines the balancing mode, and attaches a health check.
- Backends: Instance groups, network endpoint groups, or serverless backends such as Cloud Run that actually serve the traffic.
- Health check: A probe that regularly tests each backend instance and removes failing instances from rotation.
This architecture also gives you built-in DDoS protection through Google Cloud Armor integration, and TLS termination at the edge, which reduces latency for distant users.
Prerequisites
- A Google Cloud project with billing enabled and the Compute Engine API activated.
- The Google Cloud CLI (gcloud) installed and authenticated, or access to the Cloud Console.
- A registered domain name, with the ability to add a DNS A record pointing to the load balancer IP.
- At least one running Compute Engine instance or a managed instance group serving HTTP traffic on port 80, for example a simple web server. If you still need to build the backend VMs, start with our guide on how to create and harden a Compute Engine VM on Google Cloud.
- A static external IP address reserved for the load balancer, or you can reserve one during setup.
Step 1: Create a Health Check
A health check is mandatory for backend services. Without it, the load balancer cannot know which instances are healthy, and traffic may be sent to a dead instance. Create an HTTP health check that probes the root path every 10 seconds:
gcloud compute health-checks create http web-health-check \
--port 80 \
--request-path / \
--check-interval 10s \
--timeout 5s \
--healthy-threshold 2 \
--unhealthy-threshold 3
Make sure your firewall rules allow health check traffic from Google’s probe ranges (35.191.0.0/16 and 130.211.0.0/22). Without this rule, every instance will appear unhealthy:
gcloud compute firewall-rules create allow-health-checks \
--allow tcp:80 \
--source-ranges 35.191.0.0/16,130.211.0.0/22 \
--target-tags web-server \
--description "Allow Google Cloud health check probes"
Step 2: Create an Instance Group and Backend Service
Next, group your instances and attach them to a backend service. If you already have an unmanaged instance group, you can use it directly. Otherwise, create a managed instance group from an instance template. Then create the backend service:
gcloud compute backend-services create web-backend \
--protocol HTTP \
--port-name http \
--health-checks web-health-check \
--global
Add your instance group as a backend:
gcloud compute backend-services add-backend web-backend \
--instance-group web-instance-group \
--instance-group-zone europe-west1-b \
--global
For production workloads, set a balancing mode and capacity. The default utilization-based balancing works well for most web applications, but you can cap connections per instance if your application is CPU-bound:
gcloud compute backend-services update web-backend \
--balancing-mode UTILIZATION \
--max-utilization 0.8 \
--global
Step 3: Create a URL Map for HTTPS Traffic Routing
The URL map is where google cloud load balancer routing rules live. A simple map sends all traffic to one backend, while a more advanced map routes by path. Create a basic map first:
gcloud compute url-maps create web-url-map \
--default-service web-backend
To route API traffic to a separate backend, add a path matcher after creating that second backend service:
gcloud compute url-maps add-path-matcher web-url-map \
--path-matcher-name api-matcher \
--default-service web-backend \
--path-rules '/api/*=api-backend' \
--new-hosts example.com
This is the pattern behind most real deployments: one frontend, one URL map, and several backends selected by host or path. Test your map carefully in staging, because a typo in a path rule silently sends traffic to the default backend.
Step 4: Provision a Managed SSL Certificate
Google-managed certificates are free, auto-renewed, and the simplest choice for most sites. Create one for your domain:
gcloud compute ssl-certificates create web-cert \
--domains example.com \
--global
A managed certificate only becomes active after your domain’s DNS points to the load balancer IP, which you will set up in the next step. Certificate provisioning can take up to 60 minutes. Check its status with:
gcloud compute ssl-certificates describe web-cert --global
If you need a certificate immediately, or you use a private certificate authority, upload your own certificate instead and attach it to the same target proxy. For full details on certificate types and provisioning states, see the official Google Cloud HTTPS load balancing documentation.
Step 5: Create the HTTPS Proxy and Forwarding Rule
Now connect the URL map, certificate, and external IP into a working frontend. First create the target HTTPS proxy:
gcloud compute target-https-proxies create web-https-proxy \
--url-map web-url-map \
--ssl-certificates web-cert \
--global
Reserve a static IP address if you have not already:
gcloud compute addresses create web-lb-ip --global
Then create the forwarding rule that binds the IP to the proxy on port 443:
gcloud compute forwarding-rules create web-https-rule \
--address web-lb-ip \
--target-https-proxy web-https-proxy \
--ports 443 \
--global
Point your domain’s DNS A record at the reserved IP address. Once DNS propagates and the certificate is active, your site serves HTTPS through the load balancer.
Step 6: Redirect HTTP to HTTPS
Users will still type plain http URLs, so redirect that traffic instead of serving duplicate content. Create an HTTP proxy with a redirect URL map:
gcloud compute url-maps create http-redirect-map \
--default-url-redirect https-redirect \
--global
gcloud compute target-http-proxies create web-http-proxy \
--url-map http-redirect-map \
--global
gcloud compute forwarding-rules create web-http-rule \
--address web-lb-ip \
--target-http-proxy web-http-proxy \
--ports 80 \
--global
Test both addresses after setup: the HTTP URL should return a 301 redirect to HTTPS, and the HTTPS URL should return your application with a valid certificate chain.
Verifying Your Google Cloud Load Balancer Setup
Run these checks before announcing the new endpoint:
- Backend health: In the console, open the backend service and confirm every instance shows healthy. An unhealthy backend means the health check path, port, or firewall rule is wrong.
- Certificate status: Confirm the managed certificate shows ACTIVE, not PROVISIONING. A certificate stuck in provisioning almost always means DNS does not yet point to the load balancer IP.
- Routing: Request a known path such as
/api/healthand confirm it reaches the correct backend, not the default one. - Logging: Enable backend service logging and review a few requests in Cloud Logging to confirm the client IP, status code, and backend latency look correct.
Troubleshooting
All backends show unhealthy
Check the firewall rule first. Health check probes come from 35.191.0.0/16 and 130.211.0.0/22, and a missing rule is the most common cause. Next, verify the application actually responds on the health check path and port from inside the instance, and that the instance tag matches the firewall rule target.
Certificate stays in PROVISIONING
Confirm the DNS A record points to the load balancer’s static IP and has propagated worldwide. Also confirm the domain is not behind another proxy that hides the load balancer IP, because Google must be able to validate domain control.
502 errors from the load balancer
A 502 usually means the backend closed the connection or took too long to respond. Check that the backend service protocol matches what the application serves, that the application listens on the expected port, and that the backend timeout is longer than the application’s slowest response.
Traffic goes to the wrong backend
Review the URL map path matchers in order. The first matching rule wins, and unmatched requests fall through to the default service. Use the load balancer’s logging to see which backend served each request.
Conclusion
A google cloud load balancer gives you a single global frontend, managed TLS, path-based routing, and automatic removal of unhealthy instances, all without running your own proxy servers. The setup follows a fixed sequence: health check, backend service, URL map, certificate, proxy, and forwarding rule, plus an HTTP-to-HTTPS redirect for completeness. Get the firewall rules and DNS right, verify backend health and certificate status before launch, and you will have an HTTPS frontend that scales with your application and stays available when individual instances fail.