In my previous post, I did a test and talked about how fast CDN is by Google. I covered briefly enabling, and many of you asked to explain in detail.

Introduction

Cloud CDN by Google is a low-latency content delivery solution for small to enterprise businesses. With more than 130 POP (point of presence) worldwide and accelerated content delivery using Google’s global premium network, make the fastest SSL CDN globally. The latest report by CDNPerf showing Google Cloud CDN performs better than Azure, AKAMAI, Cloudflare, Fastly, and many others. Some of the features of Google Cloud CDN:

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

Pre-requisite

Wondering why pre-requisite? Well, Google CDN only works with Google load balancer and cloud storage 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 VM as origin too. It can be enabled only on the load balancer. Let’s get it started…

Scenario

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

Create a health checkCreate an instance groupCreate a load balancerEnable CDN

Creating a health check

A health check is essential for the load balancer to determine if the 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 root. Health criteria – adjust as necessary

Click create

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

Creating an instance group

The instance group is used in the load balancing setup. It’s called backend services for LB.

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

Follow the wizard to provide the necessary information. Location – Select a 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

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 servicesClick “Create load balancer.”

Select the “HTTP(S) load balancing.”Enter the name of LBClick on “Backend configuration.”Click “Create a backend service.”Enter the name of the backend servicesAdd both instances group which you created earlier as a backendSelect health check which you created previouslySession affinity – select if you want the session stickinessClick create

Leave the default configuration in  “Host and path rules.” However, if you need conditional forwarding, then add as you need.Click the 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

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

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

This indicates LB is created. Let’s do some tests to ensure LB works. So, I try to access LB frontend IP, and it’s a success! 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 the 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.”

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

You should see newly created CDN on the list.

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. I hope this helps you. If you are looking to learn hands-on about Google Cloud Platform, then check out this Cloud Architecture with GCP course.

How to Implement Google Cloud CDN  - 99How to Implement Google Cloud CDN  - 47How to Implement Google Cloud CDN  - 54How to Implement Google Cloud CDN  - 24How to Implement Google Cloud CDN  - 54How to Implement Google Cloud CDN  - 75How to Implement Google Cloud CDN  - 6How to Implement Google Cloud CDN  - 13How to Implement Google Cloud CDN  - 94How to Implement Google Cloud CDN  - 23How to Implement Google Cloud CDN  - 3How to Implement Google Cloud CDN  - 65How to Implement Google Cloud CDN  - 90How to Implement Google Cloud CDN  - 43How to Implement Google Cloud CDN  - 49How to Implement Google Cloud CDN  - 96How to Implement Google Cloud CDN  - 5How to Implement Google Cloud CDN  - 10How to Implement Google Cloud CDN  - 10How to Implement Google Cloud CDN  - 77How to Implement Google Cloud CDN  - 80How to Implement Google Cloud CDN  - 16How to Implement Google Cloud CDN  - 85How to Implement Google Cloud CDN  - 63How to Implement Google Cloud CDN  - 32How to Implement Google Cloud CDN  - 50How to Implement Google Cloud CDN  - 46How to Implement Google Cloud CDN  - 80How to Implement Google Cloud CDN  - 30How to Implement Google Cloud CDN  - 34How to Implement Google Cloud CDN  - 67How to Implement Google Cloud CDN  - 3How to Implement Google Cloud CDN  - 51How to Implement Google Cloud CDN  - 16How to Implement Google Cloud CDN  - 9How to Implement Google Cloud CDN  - 4How to Implement Google Cloud CDN  - 8