Skip to content

Setting up Scale to 0

With conventional cloud platforms you need to keep at least one instance running at all times to be able to respond to incoming requests: performing a just-in-time cold boot is simply too time-consuming and would create a response latency of multiple seconds or worse.

This is not the case with KraftCloud. Based on extremely lightweight unikernel technology, instances on KraftCloud are able to cold boot within milliseconds, while providing the same strong, hardware-level isolation afforded by virtual machines.

Millisecond cold boots allow us to perform low-latency scale-to-zero: that is, as long as no traffic is flowing through your instance, it consumes no resources and so you’re not charged for it. On KraftCloud you’re only charged for when your instances do useful work for you. When the next connection arrives, KraftCloud takes care of transparently cold booting (can it be called cold booting if it’s milliseconds?) your instance and replying — all of that within a negligible amount with respect to Internet RTTs and so unbeknownst to your end users and clients.

Setting it Up

Enabling scale to 0 on KraftCloud is simple: just add the -0 flag to kraft cloud deploy when creating your instance. Let’s start an NGINX instance and set it to scale to 0:

Terminal window
git clone
cd examples/nginx/
kraft cloud deploy -0 -p 443:8080 .

This command will create the NGINX instance with scale to 0 enabled:

Terminal window
[] Deployed successfully!
────────── name: nginx-1a747
────────── uuid: 66d05e09-1436-4d1f-bbe6-6dc03ae48d7a
───────── state: running
─────────── url:
───────── image: nginx@sha256:19854a12fe97f138313cb9b4806828cae9cecf2d050077a0268d98129863f954
───── boot time: 19.81 ms
──────── memory: 128 MiB
service group: twilight-gorilla-ui5b6kwt
── private fqdn: nginx-1a747.internal
──── private ip:
────────── args: /usr/bin/nginx -c /etc/nginx/nginx.conf

Note that at first the status is listed as running in the output of the kraft cloud deploy command. Let’s check the instance’s status:

Terminal window
kraft cloud instances list

You should see output similar to:

Terminal window
nginx-1a747 standby

Notice the state is now set to standby? At first kraft cloud deploy sets the state to running, but since we specified scale to 0 via the -0 flag, KraftCloud put the instance immediately to sleep (more accurately, it stopped it, but it keeps state to start it again when needed).

You can also check that scale to 0 is enabled through the kraft cloud scale command:

Terminal window
kraft cloud scale get twilight-gorilla-ui5b6kw

which outputs:

Terminal window
uuid: 126c4ecb-4718-4a25-9f75-ac9149da9e19
name: twilight-gorilla-ui5b6kwt
enabled: true
min size: 0
max size: 1
warmup (ms): 1000
cooldown (ms): 1000
master: 66d05e09-1436-4d1f-bbe6-6dc03ae48d7a

Note the min size (0) and max size (1) fields — these mean that the service group can scale from max 1 instance to min 0 instances, meaning that scale to 0 is enabled.

Testing Scale to 0

Now let’s take this out for a spin. Try using curl or your browser to see scale to 0 (well, scale to 1 in this case!) in action:

Terminal window

You should get an NGINX response with no noticeable delay. For fun, try to use the following command to see if you can catch the instance’s STATE field changing from standby to running

Terminal window
watch --color -n 0.5 kraft cloud instance list

If you curl enough, you should see the STATE turn to a green running from time to time.

Terminal window
nginx-1a747 running

Learn More

  • The kraft cloud CLI reference, and in particular the services and scale sub-commands.
  • KraftCloud’s REST API reference, and in particular the section on service groups and autoscale.