Kubernetes
Unikraft Cloud integrates seamlessly with any Kubernetes cluster through a virtual kubelet known as Kraftlet. This is a lightweight Kubernetes node implementation which connects your cluster to Unikraft Cloud's high-performance compute instead of running real pods locally. This enables developers to deploy and manage Unikraft microVMs as if they were native Kubernetes pods.
This integration extends Kubernetes' scheduling and orchestration capabilities to the Unikraft Cloud platform. This allows workloads to take advantage of microVM-level I/O performance, security, cold start and transparent scale-to-zero efficiency while retaining full compatibility with existing Kubernetes tooling.
Upon startup, Kraftlet will register itself as a worker node with the Kubernetes API. Once Kraftlet registers itself as a node, Kubernetes can schedule Pods onto it.
Any Pod scheduled to the Kraftlet node won't run as a container within the cluster. Instead, it will run a highly optimized microVM on Unikraft Cloud. Kraftlet will manage the Pod lifecycle to make sure the apps are up and running.
Getting started
You can install Kraftlet into a Kubernetes cluster using its Helm chart:
The UKC_METRO and UKC_TOKEN variables are only for these values and the legacy CLI.
The unikraft CLI uses profiles instead.
You can check if Kraftlet is running by checking its pods:
Which should return a single pod running:
Code
You can also check if the kraftlet successfully registered as a node:
Which should, among other nodes, return Kraftlet.
Code
Examples
Below are examples of Kubernetes configurations that define Unikraft Cloud apps through Kubernetes concepts.
You will notice that each workload object defines tolerations and nodeSelector so Pods get scheduled on the Kraftlet node.
Make sure Kraftlet is up and running before trying out examples below.
Simple app
The configuration below defines an app with three replicas running the nginx image and a single Kubernetes service that exposes port 443.
For each service backed by a Pod scheduled to the Kraftlet node, Kraftlet will create a corresponding service.
In this case, Kraftlet will create three nginx instances and a single service called after the Kubernetes service that exposes port 443.
Code
You can apply the configuration with:
Code
Once applied, you can check the status of your newly created pods in the Kubernetes cluster:
Code
Your app is now managed from the Kubernetes cluster, but is actually running on the Unikraft Cloud.
To check the instances, run:
Which will return a list of instances created from pods above:
Code
As you can see, all instances have the same FQDN. This is because Kraftlet created a corresponding Unikraft Cloud service for the Kubernetes service defined in YAML above. You can check the created service with the following command:
You can now manage your app running in Unikraft Cloud via Kubernetes resources!
Stateful apps
The example below deploys a stateful app on the Unikraft Cloud that has access to a volume.
To support provisioning Unikraft Cloud volumes through Kubernetes, Kraftlet listens for changes on PersistentVolumeClaim (PVC) objects with storage class ukc-volume.
Creating a new PVC object with the specified storage class triggers Kraftlet to create a Unikraft Cloud volume and create a PV object to mark the PVC as Bound.
Below is an example PVC with the Unikraft Cloud storage class you can apply to your cluster.
Code
Once applied, you can check the created PVC status:
Code
Also, you can check the volumes on the Unikraft Cloud:
At the moment, the volume isn't attached or mounted by an instance. To create an instance that would use the volume, you can create a Kubernetes Pod that would reference the PVC:
Code
If you check the instances again, you will see a new instance created from the Pod:
And if you check the volume now, you will see it's attached and mounted by the created instance:
Kraftlet internals
This section describes how Kraftlet translates Kubernetes objects into Unikraft Cloud resources.
Ports and handlers
When Kraftlet maps a Kubernetes Service port to a Unikraft Cloud service, it derives the handler from the port number automatically:
| Port | Handler applied |
|---|---|
80 | http |
443 | tls + http |
| Any other port | tls |
This is why the example above produces 443:8080/tls+http in the service list.
Kraftlet infers tls+http from port 443.
Multi-container pods
Kraftlet maps each container in a pod to a separate Unikraft Cloud instance.
When a Pod has a single container, the Unikraft Cloud service takes the Kubernetes Service name directly.
When a Pod has more than one container, each container gets its own Unikraft Cloud service, named <service>-<container> (for example, my-svc-app and my-svc-sidecar).
Kraftlet supports init containers. Kraftlet schedules both regular containers and init containers as Unikraft Cloud instances, and deletes them together when you delete the Pod.
Resource lifecycle
When you delete a Kubernetes object, Kraftlet deletes the corresponding Unikraft Cloud resource:
| Kubernetes object deleted | Unikraft Cloud resource deleted |
|---|---|
| Pod / Deployment replica | Instance (and service group if no other Pods are backing it) |
| PersistentVolumeClaim | Unikraft Cloud volume |
Notes
-
For each Pod scheduled on Kraftlet, Kraftlet runs its containers as separate Unikraft Cloud instances rather than running them as containers. Kraftlet ensures it assigns instances to the correct Unikraft Cloud services and attaches them to the corresponding Unikraft Cloud volumes.
-
When a Pod gets scheduled on the Kraftlet node, Kraftlet fetches the existing Kubernetes service that the given Pod is backing and creates a corresponding Unikraft Cloud Service. Kraftlet allows cluster admins to manage Unikraft Cloud Services by defining a Kubernetes service backed by Pods running on Kraftlet.
-
Kraftlet listens for changes on PersistentVolumeClaim objects with storageClass
ukc-volume. For each creation of such Persistent Volume Claim (PVC) object, the Kraftlet will create a corresponding Unikraft Cloud volume and aPersistentVolumeobject to bind the PVC object to. Kraftlet allows for volume management through Kubernetes clusters.
Platform features
Kraftlet supports the following Unikraft Cloud platform features on Kraftlet-managed resources:
-
Frequently deployed workloads can go into instance templates. Templates pre-warm the snapshot, reducing cold-start latency for every new instance created from the template. When Kraftlet creates an instance from a Pod spec, you can pre-position an instance template to speed up scheduling.
-
Instances attached to a Unikraft Cloud service suspend automatically when idle. Scale-to-zero runs by default for service-backed pods and you can configure it via Pod annotations (see Annotations below).
Annotations
Kraftlet reads the following annotations from Pod and Service objects to configure Unikraft Cloud resources.
Pod annotations
| Annotation | Type | Default | Description |
|---|---|---|---|
cloud.unikraft.v1.instances/autostart | boolean | true | Whether the instance starts automatically when Kraftlet schedules the Pod. |
cloud.unikraft.v1.instances/template | string | — | Name of a pre-existing Unikraft Cloud instance template to use instead of the container image. |
cloud.unikraft.v1.instances/scale_to_zero.policy | on | off | idle | on | Enables or disables scale-to-zero for service-backed instances. |
cloud.unikraft.v1.instances/scale_to_zero.stateful | boolean | false | When true, Kraftlet retains the instance state when scaling to zero. |
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms | integer | 1000 | Idle time in milliseconds before Kraftlet suspends the instance. |
Service annotations
| Annotation | Type | Default | Description |
|---|---|---|---|
cloud.unikraft.v1.services/domain | string | — | Custom domain for the Unikraft Cloud service. For multi-container pods, prefix with the container name (cloud.unikraft.v1.services/domain.<containerName>) to set a per-container domain, or use the global annotation to derive <containerName>-<domain> automatically. |
Resources
- See Unikraft public roadmap for planned features or to suggest use cases and ideas.