Choose a Google Cloud load balancer, CDN and Cloud Armor
Pick a load balancer for a workload, place Cloud DNS, Cloud CDN and Cloud Armor, and trace a request using health-check evidence.
By Invicly Tech, , in Google Cloud Engineering and Services. About 9 minutes to read.
In short
Google Cloud has several load balancers. You pick one by the traffic type (HTTP or raw TCP/UDP), whether it faces the internet or stays internal, and whether it is global or regional. Around it sit Cloud DNS for names, Cloud CDN for caching and Cloud Armor for filtering.
Think of it like this: A load balancer is a restaurant host: it greets every guest, checks which tables are open and healthy, and sends each guest to a good one.
Explained simply
A load balancer is one front door for many servers. People visit a single address. The load balancer decides which healthy server should answer each request. If a server breaks, it stops sending traffic there.
Google Cloud has two big families. Application load balancers understand web traffic (HTTP and HTTPS) and can route by host name and path. Network load balancers work with plain TCP and UDP and do not look inside the request.
Around the load balancer you can add three helpers. Cloud DNS turns a name like www.example.com into the load balancer address. Cloud CDN keeps copies of popular files near users. Cloud Armor blocks bad traffic, such as known attack patterns or too many requests from one source.
When something breaks, work from the inside out. First ask whether the backends are healthy. Then check firewall rules for the health checks. Then look at the rules that choose a backend.
Press Play on a diagram to walk through it one step at a time.
- 1Cloud DNS
www.example.com resolves to the frontend IP
- 2Forwarding rule
Frontend IP and port
- 3Target proxy and URL map
TLS ends here; paths choose a backend
- 4Cloud Armor and CDN
Policy checks, then cache lookup
- 5Backend service
Health checks pick healthy backends
- 6Backends
Instance groups, NEGs or serverless NEGs
- Understands HTTP and HTTPS
- Routes by host and path
- Works with Cloud CDN and Cloud Armor
- Terminates TLS at the proxy
- Handles TCP, UDP and other IP protocols
- Passthrough keeps the client IP as seen by backends
- Regional for most variants
- No URL-based routing
- Browser to Load balancer and CDN: GET /logo.png1GET /logo.png
- Load balancer and CDN to Backend: Cache miss: fetch from origin2Cache miss: fetch from origin
- Backend to Load balancer and CDN: 200 with Cache-Control3200 with Cache-Control
- Load balancer and CDN to Browser: Response, stored at the edge4Response, stored at the edge
- Browser to Load balancer and CDN: GET /logo.png again5GET /logo.png again
- Load balancer and CDN to Browser: Cache hit: backend not touched6Cache hit: backend not touched
In depth
Picking a load balancer
Ask three questions. What protocol? HTTP or HTTPS points to an Application load balancer. Raw TCP or UDP points to a Network load balancer. Who are the clients? Internet users need an external load balancer; other services in your VPC need an internal one. How wide? A global external Application load balancer serves users worldwide through one anycast IP. Regional ones keep traffic in one region, which helps with data location rules. Google updates this list, so check the Choose a load balancer page before you decide.
- Global external Application: public websites and APIs.
- Regional internal Application: private microservices.
- External passthrough Network: games, custom TCP, UDP.
- Internal passthrough Network: private TCP or UDP services.
Parts of an Application load balancer
A request meets a forwarding rule (the IP and port), then a target proxy that holds the certificate, then a URL map. The URL map picks a backend service by host or path. The backend service lists the backends, the health check and options such as CDN and Cloud Armor. Backends can be managed instance groups, network endpoint groups, or serverless NEGs that point to Cloud Run. Learning these names helps because the gcloud commands create each part separately, and the console hides them behind one wizard.
- Target HTTPS proxy
- TLS certificate
- SSL policy
- URL map
- Host rule
- Path matcher
- Default service
- Backend service
- Health check
- Cloud CDN setting
- Cloud Armor policy
- Backends
Reading health checks
A health check sends a probe to each backend on a port and path. After a few failures the backend is marked unhealthy and removed from rotation. The probes come from Google ranges 130.211.0.0/22 and 35.191.0.0/16, so a firewall rule must allow those ranges to the backend port. To see the result, run gcloud compute backend-services get-health. If every backend is unhealthy, the usual causes are a missing firewall rule, a wrong port or path, or an app that returns an error to the probe.
CDN and Cloud Armor
Cloud CDN stores responses at Google edge locations. Cache mode CACHE_ALL_STATIC caches common static files; USE_ORIGIN_HEADERS follows the Cache-Control headers your app sends. A cache hit never reaches your backend, so it is faster and cheaper. Cloud Armor adds a security policy to the backend service. It has preconfigured web rules, rate limiting and IP allow or deny lists. Use preview mode first. In preview, matching requests are logged but not blocked, so you can check for false positives.
- Use Cache-Control on private pages to stop caching them.
- Start Cloud Armor rules in preview mode.
- Read the load balancer logs to see cache and policy decisions.
Learn it in 5 short steps
About 35m each. Track them with a timer in your plan.
- 1Compare application and network load balancers~35m
- 2Map frontend, backend service and backends~35m
- 3Read health-check results~35m
- 4Cache responses with Cloud CDN~35m
- 5Filter traffic with Cloud Armor~35m
Key points
- Choose by protocol first: HTTP or HTTPS means Application; other TCP or UDP traffic means Network.
- Frontend pieces are the forwarding rule, target proxy and URL map. The backend service holds backends and health checks.
- Health check probes come from Google ranges 130.211.0.0/22 and 35.191.0.0/16. Firewall rules must allow them.
- Cloud CDN is switched on per backend service. Cloud Armor policies attach to backend services too.
- When traffic fails, read backend health first, then firewall rules, then the URL map.
Key terms
Tap a card to flip it. 0/6 known
Examples
gcloud compute backend-services get-health web-backend --global
gcloud compute backend-services update web-backend --global --enable-cdn \
--cache-mode=CACHE_ALL_STATIC
gcloud compute security-policies create web-policy
gcloud compute backend-services update web-backend --global \
--security-policy=web-policyRead backend health and turn on CDN. Names are placeholders.
Fix unhealthy backends
All backends show UNHEALTHY but the app works when you connect directly. The cause is a missing firewall rule for the probe ranges. Add the rule, then read health again. The evidence is HEALTHY in the output after about a minute. Rollback: delete the rule.
gcloud compute firewall-rules create allow-health-checks --network=lab-vpc \
--direction=INGRESS --action=ALLOW --rules=tcp:80 \
--source-ranges=130.211.0.0/22,35.191.0.0/16 --target-tags=web
gcloud compute backend-services get-health web-backend --globalTry a Cloud Armor rule safely
You want to block one test address range. Create a policy, add a deny rule in preview mode, and attach it. Check the logs for matches. When satisfied, remove --preview. Cloud Armor tiers and costs vary, so check pricing first. For a free design-only exercise, draw the policy on paper.
gcloud compute security-policies create lab-policy
gcloud compute security-policies rules create 1000 \
--security-policy=lab-policy --action=deny-403 \
--src-ip-ranges=203.0.113.0/24 --preview
gcloud compute backend-services update web-backend --global \
--security-policy=lab-policyQuick reference
- HTTP or HTTPS: Application load balancer. Other TCP or UDP: Network load balancer.
- Request path: forwarding rule, target proxy, URL map, backend service, backend.
- Health check ranges: 130.211.0.0/22 and 35.191.0.0/16. Allow them in the firewall.
- Check health: gcloud compute backend-services get-health NAME --global
- Cloud CDN is enabled on the backend service with --enable-cdn.
- Cloud Armor policies attach to backend services; use --preview first.
- Cloud DNS A record points your name to the load balancer IP.
Common mistakes
- Backends show UNHEALTHY because no firewall rule allows the Google health check ranges.
- Caching pages that vary per user. Check cache mode and Cache-Control headers first.
- Turning on a Cloud Armor rule without preview mode and blocking real users.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Name the four objects between a client and the backends for an external Application load balancer.
- Exercise 2medium
Choose a load balancer for a private TCP service used only by other VMs in one region, and say why.
- Exercise 3hard
Users see old images after a deploy. Describe how to find and fix the cause.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Do I need a load balancer for one VM?
- Not always. You need one for a stable public IP with TLS, health checks, several backends, CDN or Cloud Armor.
- Is Cloud CDN a separate product to deploy?
- No. You switch it on for a backend service. You still pay for cache egress and lookups.
- Why is my site unreachable right after I create the load balancer?
- Provisioning can take several minutes, and a Google-managed certificate needs DNS to point at the load balancer before it becomes active.