Skip to content

Commit ce45063

Browse files
committed
docs(features): Add instance templates reference
Signed-off-by: Jerome Jaggi <jerome@unikraft.io>
1 parent 406cdba commit ce45063

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

pages/features/templates.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Instance Templates
3+
navigation_icon: copy
4+
---
5+
6+
Instance templates allow creating pre-initialized snapshots that serve as a base for cloning new instances.
7+
Instead of cold-booting from an image, Unikraft Cloud clones the template's snapshot, and the new instance inherits its memory state.
8+
9+
This reduces start time and ensures all cloned instances begin with identical state: warm caches, initialized connections, and loaded code.
10+
11+
## How templates work
12+
13+
A template is an instance that Unikraft Cloud has snapshotted and marked as a template.
14+
The autoscale system uses templates: the autoscale master instance acts as a template, and scale-out events clone it.
15+
16+
## Template creation modes
17+
18+
Two modes exist for creating a template:
19+
20+
| Mode | Description |
21+
|------|-------------|
22+
| **Non-prepare (cold)** | The instance transitions from stopped to template state without starting. Unikraft Cloud doesn't produce a snapshot. |
23+
| **Prepare (hot)** | The instance starts and initializes. The guest signals that initialization is complete, which triggers snapshot creation. The template includes full memory state. |
24+
25+
Use prepare templates when the template needs warm state (loaded code, initialized caches, established connections).
26+
27+
## Named and anonymous templates
28+
29+
| Type | Description |
30+
|------|-------------|
31+
| **Named** | You provide a name. The template persists and you can reuse it. Concurrent requests for the same name converge to a single template. |
32+
| **Anonymous** | No name. The template is ephemeral and Unikraft Cloud frees it after cloning the child instance. |
33+
34+
## Template chains
35+
36+
Unikraft Cloud supports nesting templates up to **4 levels** deep.
37+
You can create a template from another template, forming a chain.
38+
39+
Specify a template chain via nested `template.create_args.template` fields in the instance creation request.
40+
Each level of nesting creates an intermediate template.
41+
42+
## Template autokill
43+
44+
The `template_autokill_time_ms` field controls automatic deletion of idle templates.
45+
Unikraft Cloud bases autokill on `last_clone_time`.
46+
If a template hasn't received a clone request within the autokill timeout, the platform deletes it.
47+
48+
Unikraft Cloud reference-counts templates.
49+
A template that active instances still reference isn't deleted, even if the autokill timer has expired.
50+
51+
## Creating a template
52+
53+
Create templates in two ways:
54+
55+
1. **Nested creation**: specify template parameters in the instance creation request (`POST /v1/instances`).
56+
2. **Direct conversion**: convert an existing instance via `POST /v1/instances/templates/create`.
57+
58+
From within the guest, write to `/uk/libukp/template_instance` to signal that initialization is complete and the platform should create the template snapshot.
59+
60+
## Instance limits
61+
62+
| Limit | Value |
63+
|-------|-------|
64+
| Max template chain depth | 4 |
65+
| Max auxiliary ROMs per instance | 8 |
66+
| Max volumes per instance | 4 |
67+
| Max vCPUs per instance | 32 |
68+
69+
Templates count against the user's instance quota.
70+
No dedicated template limit exists.
71+
72+
## Learn more
73+
74+
* The `kraft cloud` [command-line tool reference](/cli/)
75+
* Unikraft Cloud's [REST API reference](/api/platform/v1)
76+
* [Autoscale](/features/autoscale): autoscale uses templates for scale-out
77+
* [Snapshots](/features/snapshots): templates use the snapshot mechanism

0 commit comments

Comments
 (0)