Cloud CDN by Google is a low-latency content delivery solution for small to enterprise business, (Content Delivery Network).

With more than 100 POP (point of presence) worldwide and accelerated content delivery using ’s global premium network make the fastest SSL CDN globally.

Some of the features of Google CDN:

  • HTTP/2 – it supports latest HTTP protocol for better
  • Low latency – all contents are served through Anycast (single ) worldwide
  • Logging – it integrates with Stackdriver to provide detailed logging of a request, hit/miss
  •  Purge cache instantly
  • Low cost


Wondering why pre-requisite?

Well, Google CDN only works with Google load balancer and cloud origins. This means if you are not hosting your application on GCP (Google Cloud Platform) then you can’t use their CDN.

In other words, it doesn’t support external origins yet. Simple.

So I assume you are hosting your application on GCP and ready to use a load balancer (LB) to use the cloud CDN.

You guessed it right; you can’t use as origin too. It can be enabled only on the load balancer.

Let’s get it started…


I’ve two VM running (one in Singapore and another in the US west). I want to load balance requests to both VM using HTTP load balancer and activate CDN on it.

I need to do the following.

  • Create a health check
  • Create an instance group
  • Create a load balancer
  • Enable CDN

Creating a health check

A health check is essential for the load balancer to determine if VM is healthy. When VM can’t respond to the query, then LB would mark that unhealthy and stop sending traffic.

  • Login to GCP and go to Health Checks under Compute Engine
  • Click “Create a health check.”

  • Follow the wizard and enter the necessary information
    • Protocol – select HTTP if your application hosted on VM will listen on port 80 and HTTPS for port 443
    • Request path – a working context .
    • Health criteria – adjust as necessary

  • Click create

It will take few seconds, and you will notice newly created health check on the list. We will use this shortly.

Creating an instance group

Instance group is used in the . It’s called backend services for LB.

  • Go to Instance groups under Compute Engine
  • Click “Create instance group.”

gcp create instance group

  • Follow the wizard to provide necessary information
    • Location – select single-zone as we are not going ahead with an auto-scaling option.
    • Zone – choose the zone where VM is running
    • Group type – tick unmanaged instance group
    • VM instances – select the VM from the list
  • Click Create

gcp instance group

Repeat the steps for creating an instance group for another VM zone.

Now, we have two instance groups. Each mapped with the VM in the respective zone.

Creating a Load Balancer

  • Go to Load balancing under Network services
  • Click “Create load balancer.”

gcp create lb

  • Select the “HTTP(S) load balancing.”
  • Enter the name of LB
  • Click on “Backend configuration.”
  • Click “Create a backend service.”
  • Enter the name of the backend services
  • Add both instances group which you created earlier as a backend
  • Select health check which you created previously
  • Session affinity – select if you want the session stickiness
  • Click create

gcp create backend

  • Leave the default configuration in  “Host and path rules”. However, if you need conditional forwarding then add as you need.
  • Click frontend configuration and enter the name
  • Select “create IP address” to get the static IP address. This is important as by default you will get ephemeral IP.
  • Protocol, IP version, and port leave it to the default
  • Click Done

gcp front end lb

  • Click on review and finalize and if you feel something is wrong then change it else click “Create.”

gcp front end lb create

  • Once created, you will notice newly created LB on the list

gcp lb created

This indicates LB is created. Let’s do some test to ensure LB works.

So, I try to access LB frontend IP, and it’s success!

gcp lb works

You may also want to generate some loads to ensure traffic is routed to both the VMs. Google will forward requests to the nearest VM from user’s geolocation.

In my scenario, traffic from Asia will go to VM in Singapore and from America, it will go to US-West VM.

Activating Google Cloud CDN

And, finally, it’s time to enable the CDN.

  • Go to Cloud CDN under network services
  • Click “Add origin.”

gcp cdn add origin

  • Select the load balancer from origin drop-down and click add

gcp add cdn

  • You should see newly created CDN on the list

google cloud cdn

This concludes CDN is enabled on the load balancer.

Once you are satisfied with it, you can update your domain’s A record to load balancer global IP.

Print Friendly, PDF & Email



Bài viết liên quan