GCP load balancer with autoscale quick setup¶
Overview¶
WCS Google Cloud Platform instances support TCP Network load balancer.
WebSocket connections will be distributed between active load balancer instances. In case a scaling policy is executed (when the policy target – e.g., CPU load on instance - is reached) and new instances are launched, they will be added to the load balancer.
The following components would be required
- Disk image to use in instance template
- Instance template to create new server instances while autoscaling
- Autoscale instance group
- Load balancer
- Server health checks
Let's try to deploy CDN for WebRTC streams including one Origin server and a group of Edge servers (from 1 to 3 instances) with CPU load autoscaling.
Prepare server instances¶
-
Create one Origin and one Edge server as described here. Reserve a static internal IP address to Origin server. Reserve external static IP address to use in load balancer
-
Configure CDN on Origin server side
-
Configure CDN on Edge server side
-
Add the following parameter to Edge server settings
-
Prepare and import SSL certificates to Origin and Egde servers. It is nor recommeded to use Let'sEncrypt because it requires to update Edge disk image every 3 months.
Create Edge disk image¶
-
Stop Edge server instance
-
In Google Cloud console, go to
Compute Engine-Imagessection and clickCreate image. Choose Edge instance disk as disk image source and clickCreate

Do not delete source Edge instance after disk image creation, it will be necessary for Edge disk image updating.
Create Edge instance template¶
-
Go to
Compute Engine-Instance templatessection and clickCreate instance template. Choose instance VM configuration

-
In
Boot disksection clickChange

OnCustom imagestab choose Edge disk image

-
On
Securitytab add the public SSH key if you do not have project SSH keys and clickCreate

Create autoscaling group¶
-
Go to
Compute Engine-Instance groupssection and clickCreate instance group. Choose instance group region and zone, select Edge instance template

-
Choose
Autoscalemode byCPU utilizationmetric, set metric target value to80%and set maximum number of instances to3

-
Enable
Auto healingand create a health check. Set TCP protocol, port8081and request/health-check

Configure health criteria and clickCreateto return to group setup

-
Expand
Advanced creation optionsand enableDo not retry machine creation, then clickCreate

Autoscaling instance group will be created, and one instance will be launched

Create load balancer¶
-
Go to
Network–Load balancerssection and clickCreate load balancer. ChooseTCP Load Balancing

-
Choose external load balancer
From internet to my VMsand its region

-
In
Backend configurationsection, onSelect existing instance groupstab select Edge instance group and set session affinity to client IP and protocol

-
Choose
Create health check. Create server health check, set port8081and request/

-
In
Frontend configurationsection create TCP port configurations for ports8081,8080,8443,8444for HTTP(S) and WS(S). Set external static IP address to load balancer


You can add another port configurations (1935for RTMP subscribers,8082,8445for HLS etc depending on Edge use case) -
Click
Create. Load balancer will start

Load balancer testing¶
-
Go to Origin web interface and publish
teststream in Two Way Streaming example -
Go to Edge web interface using load balancer IP address. Play the
teststream in Player example

Updating Edge servers settings¶
To update Edge servers settings, for example, to update SSL certificates, Edge disk image must be updated as follows:
-
Disable autoscaling and delete all Edge instances in Edge instance group
-
Launch source Edge server instance
-
Update the settings as needed (for example, update SSL certificates)
-
Stop source Edge instance
-
Delete Edge disk image
-
Create new Edge dick image with the same name (for example,
test-edge-image-1) -
Enable autoscaling in Edge instance group (autoscaling settings will be preserved)