Skip to content

Autoscaling services

HyperCloud provides many options for auto-scaling services based on a number of different policies - from utilization to time-based. These instructions create a very simple web service, based on Alpine Linux, which will scale based on CPU load.

Adding a New Network Reservation

Adding a network reservation makes it easier to set up a load balancer:

  • Navigate to Network -> Virtual Networks
  • Put a tick in the box next to the network you want to use, click the green dropdown button, and select 'Reserve'.

    Virtual Network Reservation VNet List

  • Specify the number of addresses required (3 for this example)

  • Add a Virtual Network Name

Optional

Under Advanced Options you can choose the First Address in the reservation; otherwise, it will just select the next available address in the range.

  • Click the green reserve button.

    Autoscaler VNet Reservation

Download Alpine Linux

Make sure you have downloaded the Alpine Linux 3.15 image from the marketplace:

For this example, the Alpine Linux 3.15 Template was cloned and renamed Web Host Scalable.

VM Scalable Template

Updating the Image Template

To update the Template:

  • Set Physical CPU to 0.1
  • Set Virtual CPU to 1
  • Leave RAM at 128 MB
  • Add a network connection to the reservation created above - make sure it has access to the internet so that software can be installed.

  • Edit the context and add the following to the Start script box:

#!/bin/bash
apk add mini_httpd
mkdir /www
chown mini_httpd /www
cat << EOF > /etc/mini_httpd/mini_httpd.conf
## do not leave empty lines in here!
#host=www.example.org
port=80
user=minihttpd
dir=/www
nochroot
EOF
cat << EOF > /www/index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>HTML5</title>
</head>
<body>
    Server is $HOSTNAME
</body>
</html>
EOF
ip route add 172.16.60.0/24 via 10.199.0.15
rc-service mini_httpd start

Note

The route highlighted above was for use with a load balancer, which is explained in the Load Balancer section - you may or may not need something similar.

Creating the Auto-scaling Service

Navigate to Templates -> Services and click the green + button to create a new service.

  • Input a Name
  • Expand the Network Configuration and add a Mandatory Network to your service network. Use the IP Address Reservation created above

    Service Template Net Config

  • Expand the Advanced Service Parameters and set the VM shutdown action to Terminate hard

    Advanced Service Parameter

  • Add a Role name and select the VM Template created earlier

    Auto Scaler Role Name

  • Expand the Role elasticity and set parameters

    • Set Type (to describe what should happen) to Change, to Add/Subtract the given number of VMs
    • Set Adjust to 2, which will define how many VMs to instantiate with this change
    • Input Expression with CPU > 50, which will define when this action will trigger, i.e. when CPU utilization is at more than 50% for Period in seconds
    • The # field will be set to 1, which represents the number of periods that the expression must output true before the elasticity is triggered
    • Set the Period to 5, which is the duration of the Periods, in seconds
    • Set the Cooldown to 10, which is the cooldown period duration after a scale operation, in seconds

Production note

Both Period and Cooldown will likely be set to a longer duration in a production deployment.

  • Add a second policy rule to shrink the cluster when CPU utilization normalizes, in this case, less than 50%

    • The Type, Expression, Period, and Cooldown will remain the same.
    • Set the Adjust to -2, to remove two VMs
    • Set the # to 2

      Service Role Elasticity

  • Click the green Create button at the top of the form.

  • Navigate to the Templates -> Services list page and click the newly created Template and then the green dropdown button to instantiate it.

In Instances -> VMs you should see a single instance of the VM running with a name similar to webscaler_2_(service_14); furthermore, you will find, under Instances -> Services, the new Service initializing or in the Running State.

Note

The green + Scale button will allow instant manual scaling of the cluster.

  • Click on the Service to bring up the Info screen.

    • Select Roles to show the details of the roles which make up the Service.
      • A positive number (e.g. 2) will be used to increase and a negative number (e.g. -2) will be used to decrease.
      • Also, make notice of the list of VMs that show the VMs currently controlled by this Service.
        • The command oneflow show [service number] will provide the same details shown in the GUI.

    Service Webscaler Roles

The Log tab displays the archive of the system's scaling and descaling states.

Service Webscaler Log

Use a system with access to the network to check that the web service is listening:

jumphost:~ # curl http://10.199.0.14
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>HTML5</title>
</head>
<body>
    Server is webscaler-2--service-14
</body>
</html>

Note above the Server is [hostname] line.

For a simple way to trigger the scaling, SSH into the VM and run: webscaler-0--service-14:~# cat /dev/zero > /dev/null

  • After a few seconds (5 in this case), refreshing the Instances -> VMs screen with the green + button should show two new VMs initializing.

  • Check that the two new VMs are accessible using the curl command shown above, ensuring that a different hostname for each is shown.

Note

Using a nested HyperCloud environment for this test can mean that the VMs take quite some time to actually boot.

  • Cancel the cat command above and wait to ensure that the Cluster is scaled back CPU load drops, two of the VMs will be terminated.

Warning

The VM logged into may be terminated as the service does not always maintain the original VM.

This completes the Auto-Scaling Service example instructions, the next logical step is to create a Load Balancer, which can be found in its respective section.