Unikraft Cloud supports the ability to deploy stateful apps. These apps can keep state across different scale-to-zero incarnations. This mechanism also reduces app init time. Heavy-weight apps take a while to get started when cold started (for example, Spring Boot, Ruby on Rails, etc.). You can reduce this initialization time by taking a snapshot of the app memory and restoring it when the app starts again.
Setting it up
The quickest way to set this up is via the --scale-to-zero-stateful flag of
the kraft cloud deploy or kraft cloud instance create commands, for example:
As an alternative, you can add a label to your example's Kraftfile as follows:
You can see an example of such a Kraftfile and label in the Spring Boot example.
Once deployed, you can check whether this mechanism works for your app via the kraft cloud instance get <instance name> command:
How it works
When you enable stateful mode and first deploy your app, Unikraft Cloud brings it up normally and lets it fully initialize (which may be fast, or take seconds or minutes, depending on your app's init time). Unikraft Cloud waits until the app's exposed port becomes available, and then starts the scale-to-zero process (assuming no traffic is coming to that port). At this point, Unikraft Cloud saves the state of your app, and sets the app to standby (consuming no resources).
Next, when traffic arrives, Unikraft Cloud brings up the app including its saved state, ensuring statefulness across different scale-to-zero and scale-to-one cycles, but also eliminating any long initialization times from heavyweight apps.
Learn More
- The
kraft cloudcommand-line tool reference, and in particular thedeployandinstancesubcommands. - Unikraft Cloud's REST API reference, and in particular the scale-to-zero schema.