Unikraft Cloud supports scaling instances to zero based on different triggers. This allows you to optimize resource usage and costs by automatically setting instances to standby when they're not needed. They will automatically resume when required with minimal delay. The platform can scale down instances automatically, or you can scale them down manually. You can read more about Scale To Zero here.
Automatic triggers
Automatic triggers are the most common and easiest way to use scale-to-zero with your instances on Unikraft Cloud. By default, instances scale down automatically when there is no traffic coming to them for a specified period. You can also configure scale-to-zero to consider idle active connections when determining whether to scale down an instance.
No traffic
When you enable this trigger, Unikraft Cloud will track incoming connections to your instance.
If there is no traffic for the configured duration, the instance scales down to zero.
You can use the kraft CLI tool or the API to enable this trigger:
Code
Idle connections
When enabling this trigger, the platform will consider all active connections to your instance, so all traffic going to them. The instance will scale down if you make no new network connections and all existing connections have been idle for the configured duration.
You can enable this trigger using the kraft CLI tool or the API as follows:
Code
If your app uses keep-alive messages over this active connection, your instance won't scale down. You will have to either disable keep-alive or configure them with an interval high enough to allow scaling down. For example, with a 5 seconds cooldown, you can set keep-alive to once per minute.
Manual triggers
For specific use cases, you might want to manually scale your instances to zero, or to manually disable scale-to-zero. Unikraft Cloud supports two ways to manually trigger scale-to-zero.
API
You can use the Unikraft Cloud API to manually scale down an instance.
You will have to use the /instances/suspend endpoint to scale down an instance.
This happens instantly, regardless of the configured automatic triggers.
First, set the required environment variables:
Code
Then invoke the following curl command to scale down an instance named my-instance:
Code
Device file
You can also manually scale down an instance by writing '+'/'-' to a special device file available inside the instance.
Every instance has this file at /uk/libukp/scale_to_zero_disable.
By writing '+' to this file, you disable automatic scale-to-zero for the instance until the number of '-' written matches the number of '+' written.
For example, to disable automatic scale-to-zero, run the following command inside the instance:
Code
If your app starts listening for incoming connections before being ready to serve them, you can use this mechanism to disable scale-to-zero during startup. Once your app is ready to serve requests, you can write '-' to the file to re-enable automatic scale-to-zero.
Learn more
- The Scale To Zero feature page.
- The
kraft cloudcommand-line tool reference, and in particular the instance create subcommand.