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
-Images
section 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 templates
section and clickCreate instance template
. Choose instance VM configuration
-
In
Boot disk
section clickChange
OnCustom images
tab choose Edge disk image
-
On
Security
tab add the public SSH key if you do not have project SSH keys and clickCreate
Create autoscaling group¶
-
Go to
Compute Engine
-Instance groups
section and clickCreate instance group
. Choose instance group region and zone, select Edge instance template
-
Choose
Autoscale
mode byCPU utilization
metric, set metric target value to80%
and set maximum number of instances to3
-
Enable
Auto healing
and create a health check. Set TCP protocol, port8081
and request/health-check
Configure health criteria and clickCreate
to return to group setup
-
Expand
Advanced creation options
and 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 balancers
section and clickCreate load balancer
. ChooseTCP Load Balancing
-
Choose external load balancer
From internet to my VMs
and its region
-
In
Backend configuration
section, onSelect existing instance groups
tab select Edge instance group and set session affinity to client IP and protocol
-
Choose
Create health check
. Create server health check, set port8081
and request/
-
In
Frontend configuration
section create TCP port configurations for ports8081
,8080
,8443
,8444
for HTTP(S) and WS(S). Set external static IP address to load balancer
You can add another port configurations (1935
for RTMP subscribers,8082
,8445
for HLS etc depending on Edge use case) -
Click
Create
. Load balancer will start
Load balancer testing¶
-
Go to Origin web interface and publish
test
stream in Two Way Streaming example -
Go to Edge web interface using load balancer IP address. Play the
test
stream 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)