Autoscale
Autoscaling is load balancing where the number of instances used to handle your traffic is automatically adapted to match the current traffic load. On Unikraft Cloud (UKC), scale out (the process of adding instances to cope with increased load) happens in milliseconds, so 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 just set autoscale on and let UKC handle your traffic increases and peaks.
The Basics
As with load balancing, autoscaling in UKC is handled via a service. Services allow you to load balance traffic for an Internet-facing service like a web server by creating multiple 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, and always keeping a large number of instances running just to cope with intermittent bursts would be wasteful and expensive; this is where autoscale comes into play.
With autoscale enabled, UKC 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 on UKC accounts (you
might get a "Autoscale not enabled for your account" error). If you would like
us to enable it for you please reach out to us on the UKC Discord or send an
email to support@unikraft.com
.
Autoscale as well as load balancing in general is currently only available for Internet-facing services.
Setting up Autoscale
First, we'll use the kraft cloud deploy
command to create an instance, in this
example we'll use NGINX:
With this single kraft cloud deploy
command we've accomplished 3 things:
- Created an instance of NGINX which we will use as the autoscale master instance.
- Created a service via the
-p
flag (namedsmall-leaf-rafirkw7
). - Attached the instance to the service (automatically done by the
-p
flag too).
All that's left to do now to set up autoscale is to set an autoscale
configuration policy and to set our instance as master; UKC will then take
care of cloning this master instance whenever load increases. To achieve this
we'll use the kraft cloud scale
command:
Note the following:
- With the first command we set the master to the instance we created, and say that we want to scale up to a maximum of 8 instances and a minimum of 1; we also set the warm up and cool down time to 1 second each, so we're not constantly fluctuating up and down.
- With the second command we set the scale out policy based on CPU utilization
- (in millicores): between 60% and 80% utilization, increase by 50% of
- instances. From 80% onward, double the number of instances.
- With the third command we set the scale in policy: below 50% utilization,
reduce the number of instances by half (note the
-
sign for scale in).
The intervals which are used for autoscale to make scale-out and scale-in decisions are controlled with 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.
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 similar to:
To list an individual policy, you can further use the kraft cloud scale get
command as follows:
You should see output similar to:
You can further check that the master instance is on standby
, i.e., it has
been scaled to 0 (assuming your service isn't receiving any traffic yet). You
can get the UUID
of your master instance from the kraft cloud scale get
command above.
You should see output similar to:
Note the value of the state
field. Now let's make sure the service is up:
Code
You should get an immediate response, even though the instance was on standby
.
You can use the watch
tool to see if you manage to see the instance change
state from standby
to running
:
Learn More
- The
kraft cloud
CLI reference, and in particular the scale sub-command - Unikraft Cloud's REST API reference, and in particular the section on autoscale