Zudoku
Features

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, 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 isn't enabled by default on Unikraft Cloud accounts (you might get a "Autoscale not enabled for your account" error). If you would like to enable it for you please reach out to the Unikraft Cloud 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, use the kraft cloud deploy command to create an instance, in this example using NGINX:

(bash)
git clone https://github.com/unikraft-cloud/examples cd examples/nginx/ kraft cloud deploy -p 443:8080 .
(ansi)
[] Deployed successfully! ────────── name: nginx-4d7u3 ────────── uuid: 8fda2a70-6a32-4b5e-8900-4395b33d02d7 ───────── state: running ─────────── url: https://small-leaf-rafirkw7.fra.unikraft.app ───────── image: nginx@sha256:389bfa6be6455c92b61cfe429b50491373731dbdd8bd8dc79c08f985d6114758 ───── boot time: 20.36 ms ──────── memory: 128 MiB ─────── service: small-leaf-rafirkw7 ── private fqdn: nginx-4d7u3.internal ──── private ip: 172.16.6.5 ────────── args: /usr/bin/nginx -c /etc/nginx/nginx.conf

With this single kraft cloud deploy command, 3 things happen:

  1. Creates an instance of NGINX which will serve as the autoscale master instance.
  2. Creates a service via the -p flag (named small-leaf-rafirkw7).
  3. Attaches 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 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:

(bash)
kraft cloud scale init small-leaf-rafirkw7 \ --master nginx-4d7u3 \ --min-size 1 \ --max-size 8 \ --warmup-time 1s \ --cooldown-time 1s kraft cloud scale add small-leaf-rafirkw7 \ --name scale-out-policy \ --metric cpu \ --adjustment percent \ --step 600:800/50 \ --step 800:/100 kraft cloud scale add small-leaf-rafirkw7 \ --name scale-in-policy \ --metric cpu \ --adjustment percent \ --step :50/-50

Note the following:

  • The first command sets the master to the instance created, and sets it to scale up to a maximum of 8 instances and a minimum of 1; the warm up and cool down time are also set to 1 second each, so it's not constantly fluctuating up and down.
  • The second command sets the scale out policy based on CPU utilization (in millicores): between 60% and 80% utilization, an increase by 50% of instances occurs. From 80% onward, the number of instances doubles.
  • The third command sets the scale in policy: below 50% utilization, reduce 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 there are a few restrictions on how to define scale-in/scale-out steps. The documentation is available here at the bottom of the section. General information about autoscale is available here

Testing it

To check it's working, you can use the kraft cloud scale get command to list the autoscale properties of the service:

(bash)
kraft cloud scale get small-leaf-rafirkw7

You should see output like:

(ansi)
uuid: 5ca059ec-a24a-41f2-8413-f09bc58730ca name: small-leaf-rafirkw7 enabled: true min size: 0 max size: 8 warmup (ms): 1000 cooldown (ms): 1000 master: f840ac12-f485-4f02-9f33-6a0a7de46f1f policies: scale-out-policy;scale-in-policy

To list an individual policy, you can further use the kraft cloud scale get command as follows:

(bash)
kraft cloud scale get --policy scale-out-policy small-leaf-rafirkw7

You should see output like:

(ansi)
adjustment_type: percent enabled: true metric: cpu name: scale-out-policy status: success steps: - adjustment: 50 lower_bound: 600 upper_bound: 800 - adjustment: 100 lower_bound: 800 type: step

You can further check that the master instance is on standby (scaled to zero) 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.

(bash)
kraft cloud instance get f840ac12-f485-4f02-9f33-6a0a7de46f1f -o list

You should see output like:

(ansi)
uuid: f840ac12-f485-4f02-9f33-6a0a7de46f1f name: nginx-9mbf2 fqdn: restless-resonance-0oo7m7s8.fra.unikraft.app private ip: 172.16.6.4 state: standby created at: 30 minutes ago image: nginx@sha256:d4325c1f1a472c511723148adc380d491029f4c98a2367fbeff628c6456d4180 memory: 128 MiB args: /usr/bin/nginx -c /etc/nginx/nginx.conf env: volumes: service : 5ca059ec-a24a-41f2-8413-f09bc58730ca boot time: 19465us

Note the value of the state field. Now to make sure the service is up, curl the service address:

Code(bash)
curl https://small-leaf-rafirkw7.fra.unikraft.app

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:

(ansi)
watch --color -n 0.5 Unikraft Cloud instance list

Learn more

Last modified on