Step By step tutorial with real time example on how to create application layer 7 load balancer in GCP.
Load Balancer in GCP is used to distribute user traffic across instances of an application in single region or multiple regions.
It is fully distributed software defined managed service. Google cloud platform will ensure that this service is highly available.
Feature of Google Cloud Load Balancer:
- Auto Scaling – Based on number of requests cloud load balancing will automatically scale.
- Health check – This will help cloud load balancer to route traffic to only healthy instances.
- Global Load Balancing with single anycast IP – Google cloud load balancer comes with single anycast IP. This IP receives traffic across multiple regions and zones.
- Enables high availability, autoscaling and Resiliency.
This is Handon’s tutorial, and you can follow along.
Google cloud offers free credits worth 400 $ to learn and explore google cloud platform using free trial account. Learn more on how to create google cloud free trial account Google Cloud Free Credits – Google Cloud Tutorials .
HTTP vs HTTPS vs TCP vs UDP protocols
When 2 systems talk with each other communication happens over multiple layers. The Important layers are as below.
Network Layer (Layer 3) – Responsible to transmit bits and bytes of data packages. It uses IP (Internet Protocol) protocol. It is unreliable hence transport layer is required to validate data.
Transport Layer (Layer 4) – Responsible to ensure bits and bytes transferred from sender are received correctly at the receiver.TCP protocol is used at this layer. It is highly reliable protocol. If 10 bytes are transferred from one system to another TCP protocol is responsible to ensure all the bytes are received correctly and in correct order. Transport layer also supports TLS (Transport layer security) protocol. It is used version of TCP.
Transport Layer also supports UDP (User Datagram protocol). It gives more preference to performance over reliability. This is suitable for communication in scenarios like gaming, video streaming applications where performance is more important over reliability.
Application Layer (Layer 7) It is top of the chain. Used to make REST API calls, Send Emails.
It supports HTTP (Hypertext transfer protocols) use to make Web applications and API requests.
HTTPS (Secured HTTP). It used certificates installed on servers to ensure communication between systems is secured.
Top layer depends on layer beneath it for communication. Not all applications communicate at application layer. In case of video streaming applications where speed is critical such applications can communicate at transport layer using TCP/UDP protocol.
Create a Load Balancer in GCP
Log into Google Cloud console and search ‘load balancing’ in google console search box.
Load balancer is part of network services.
Google cloud supports 3 types of load balancers.
- Application Load Balancer (HTTP/S) : Layer 7 load balancing for HTTP and HTTPS applications
- Network Load Balancer (TCP/SSL) : Layer 4 load balancing or proxy for applications that rely on TCP/SSL protocol
- Network Load Balancer (UDP): Layer 4 load balancing for applications that rely on UDP protocol
In this article we will configure Application Load Balancer (HTTP/S).
Click on start configuration.
In this demo we will create Layer 7 Application load balancer. It enables you to run and scale your services behind the scenes exposing single IP address.
You can pick a load balancer depending on the needs of your application and the type of traffic that it needs to handle.
Depending on the type of traffic handled by load balancer select load balancer traffic source. In this article we will use From Internet to my VMs or serverless services.
If you microservices are hosted globally across multiple regions and zones Global external Application Load Balancer is prefer choice.
GCP also supports classic and regional load balancers.
Application load balancer can be deployed externally or internally depending on whether the application is internet facing or internal application.
Inside load balancer there are 3 critical configurations
Backend configuration, Path Rules and front-end configuration.
Backend: Group of end points that receives traffic from google cloud load balancer.
Application load balancer distributes incoming HTTP, HTTPS traffic to variety of backends hosted on Google cloud platform such as GKE,Virtual machines. In this demo we will use Group of virtual machines (MIG) as backend.
Frontend: Specify an IP address, port and protocol.
Host and Path Rules: Define rules for redirecting traffic to different backend services.
In our case our Backend Is managed instance group.
To learn more about MIG configuration in Google Cloud refer Google Cloud Managed Instance Group – Google Cloud Tutorials
Click on Backend configuration and click on create a Backend service.
Enter valid Name and description for load balancer.
Select Backend type as Instance Group and HTTPS protocol.
In the backends section select your MIG.
For HTTPS traffic configure port as 80.
Balancing mode is used by load balancer to determine how the load balancer distributes requests among backend instance group.
For this demo we will set balancing mode to Utilization and max utilization would be 80%.
If you are using load balancer to manage micro services architecture multiple Backends can be configured as per requirement.
Cloud CDN feature is used to cache and serve static website content including JavaScript and CSS files.
Click on health check to configure new health check rules.
Health check rules are used to check healthy instances in MIG, and load balancer service will route traffic only to healthy instances.
In Microservices architecture host and path rules are used to route traffic to different backend services depending on path rules.
Enter valid name for frontend and use HTTPS protocol.
Review your request and click on create.
It would take around 8-10 minutes for Google cloud platform to set up gcp global load balancer.
Navigate to network configuration and click on load balancing.
Click on load balancer created in step1 to check more details.
Enter the load balancer IP address in your browser tab to check traffic routing using google cloud load balancer.
How to Choose load balancer ?
To determine which load balancer to use among all the available choices in google cloud platform it is important to first understand traffic type handled by load balancer.
As a general rule, you’d choose an Application Load Balancer to handle HTTP HTTPS requests. This is best suited to handle Web request, API requests.
If the application is Internet facing use external Application load balancer.
For applications within organization network use Internal Load balancer.
If application is distributed across multiple regions and zones use global external application load balancer.
For regional loads use regional external application load balancer.
For details on network layer balancer types refer Cloud Load Balancing overview | Google Cloud
For detailed pricing on google cloud load balancer refer Cloud Load Balancing | Google Cloud.
What is a load balancer in GCP?
Load Balancer in GCP is fully distributed software defined managed service used to distribute user traffic across instances of an application in single region or multiple regions.
How many types of load balancer are there in GCP?
Google cloud supports 2 main types of load balancers.
Layer 7 Application load balancers
Layer 4 Network load balancers
You’d choose an Application Load Balancer when you need a Layer 7 load balancer for your applications with HTTP(S) traffic. You’d choose a Network Load Balancer when you need a Layer 4 load balancer that supports TLS offloading (with a proxy load balancer) or you need support for IP protocols such as UDP, ESP, ICMP, and so on (with a passthrough load balancer).
What is the difference between L4 and L7 load balancer GCP?
Layer 4 load balancing is used to handle traffic at transport layer and network layer. Supported protocols at this layer are TCP, TLS,UDP,ICMP,ICMPV6.
Layer 7 load balancer works at application layer and used to handle traffic for Web requests/API requests.
Protocols supported at this layer includes HTTP, HTTPS