Autoscaling is load balancing where the number of instances used to handle your traffic automatically adapts to match the current traffic load. On Unikraft Cloud, scale-out (the process of adding instances to cope with increased load) happens in milliseconds. You can transparently and effortlessly handle load increase including traffic peaks. No more headaches due to slow autoscale like keeping hot instances around to deal with peaks, coming up with complex predictive algorithms, or other painful workarounds. You can set autoscale on and let Unikraft Cloud handle your traffic increases and peaks.
The basics
As with load balancing, autoscaling in Unikraft Cloud takes care of a service. Services allow you to load balance traffic for an Internet-facing service like a web server by creating many instances within the same service.
While you can add or remove instances to a service to scale your service, doing this manually makes it hard to react to changes in traffic load. Keeping many instances running to cope with intermittent bursts would be wasteful and expensive. This is where autoscale comes into play.
With autoscale enabled, Unikraft Cloud takes care of the heavy lifting for you by continuously monitoring the load of your service and automatically creating or deleting instances as needed.
Limited Access
At the moment, autoscale is not enabled by default (you might get an "Autoscale not enabled for your account" error).
If you would like to enable it, please reach out to the Unikraft Cloud Discord or send an email to support@unikraft.com.
Autoscale, as well as load balancing in general, currently supports only Internet-facing services.
Setting up autoscale
First, use the kraft cloud deploy command to create an instance, in this example using NGINX:
This single kraft cloud deploy command does 3 things:
- Creates an instance of NGINX which will serve as the autoscale master instance.
- Creates a service via the
-pflag (namedsmall-leaf-rafirkw7). - Attaches the instance to the service (the
-pflag also does this automatically).
All that's left to do now to set up autoscale is to set an autoscale configuration policy and to set the instance as master.
Unikraft Cloud then takes care of cloning this master instance whenever load increases.
To achieve this, use the kraft cloud scale command:
Note the following:
- The first command sets the master to the created instance, and configures it to scale up to a maximum of 8 instances and a minimum of 1; the command also sets the warm up and cool down time to 1 second each, so it doesn't constantly fluctuate up and down.
- The second command sets the scale-out policy based on CPU utilization (in millicores): between 60% and 80% utilization, the system increases instances by 50%. From 80% onward, the number of instances doubles.
- The third command sets the scale-in policy: below 50% utilization, the system reduces the number of instances by half (note the
-sign for scale-in).
The intervals that autoscale uses for making scale-out and scale-in decisions use the --warmup-time and --cooldown-time parameters of kraft cloud scale init, in units of milliseconds.
Refer to the API autoscale reference for more details.
Keep in mind that a few restrictions apply to how you define scale-in/scale-out steps. You can find the documentation here at the bottom of the section.
Testing it
To check it's working, you can use the kraft cloud scale get command to list the autoscale properties of the service:
You should see output like:
To list an individual policy, you can further use the kraft cloud scale get command as follows:
You should see output like:
You can further check that the master instance is on standby (scaled to zero), assuming your service hasn't received any traffic yet.
You can get the UUID of your master instance from the kraft cloud scale get command above.
You should see output like:
Note the value of the state field.
Now to make sure the service is up, curl the service address:
You should get an immediate response, even though the instance was on standby.
You can use the watch tool to see if you catch the instance changing state from standby to running:
Learn more
- The
kraft cloudcommand-line tool reference, and in particular the scale subcommand. - Unikraft Cloud's REST API reference, and in particular the section on autoscale.