MicroVM control API forFirecracker
A Rust Axum REST API for managing Firecracker microVMs — VM lifecycle, ephemeral untrusted code execution, and persistent HTTP endpoints with per-VM TAP networking across two trust-scoped deployments.
Two ecosystems by trust level
Firecracker runs in parallel deployments in the same namespace, chosen by trust level — firecracker-ctl for ephemeral untrusted code (MMDS only) and a networked ecosystem for persistent endpoints, served today by firecracker-ctl-direct.
- Untrusted — MMDS-only, edge + dashboard, ephemeral.
- Networked — direct egress (VPN pod parked), persistent, staff.
What it gives you
Features
VM lifecycle API
Create, poll status, fetch results, and destroy microVMs with per-VM timeout enforcement and in-memory state via DashMap.
Ephemeral code execution
User code booted into a VM via a raw block drive (/dev/vdb) — written, padded, attached, and exec'd by the VM init.
Persistent endpoints
Named long-lived VMs exposing HTTP servers, reached by name through the proxy routes, on the networked deployments only.
Pre-built rootfs
Alpine minimal / python / node ext4 images built in-cluster via an ArgoCD PostSync hook.
Lifecycle & rootfs
Overview
Overview
Rust Axum REST API for managing Firecracker microVMs. Provides VM lifecycle management (create, poll, destroy) with per-VM timeout enforcement and in-memory state tracking via DashMap.
Key facts
| Image | registry.gitlab.com/kbve/workspace/firecracker-ctl |
| Language | Rust (Axum) |
| Service | ClusterIP :9001 |
| License | KBVE |
| Source | services/firecracker |
| Requires | /dev/kvm, kvm=true node selector |
Features
- VM lifecycle API — create, poll status, fetch results, and destroy microVMs.
- Ephemeral code execution — user code booted into a VM via a raw block drive.
- Persistent endpoints — named long-lived VMs exposing HTTP servers (networked deployments only).
- Two ecosystems — untrusted MMDS-only VMs and networked VMs with outbound internet.
- Pre-built rootfs — Alpine minimal/python/node ext4 images built in-cluster.
API Endpoints
| Method | Path | Description |
|---|---|---|
POST | /vm/create | Create and start a microVM |
GET | /vm/{vm_id} | Get VM status |
GET | /vm/{vm_id}/result | Get stdout/stderr/exit_code after completion |
DELETE | /vm/{vm_id} | Force-terminate a running VM |
POST | /vm/quote | Price a VM request against the billing SKUs |
GET | /vm | List all VMs |
GET | /health | Service health check |
GET | /metrics | Prometheus metrics |
GET | /openapi.json | OpenAPI document |
Billing against the KBVE wallet (hold, settle, record deployment) is wired in but off unless FC_BILLING_ENABLED is set.
Code Execution Flow
- User code arrives via
env.CODEin the create request - Code is written to a raw block file (512-byte padded)
- Block file attached as second Firecracker drive (
/dev/vdb) - Entrypoint passed via
boot_args(fc_entrypoint=/usr/bin/python3) - VM init script reads code from
/dev/vdb, writes to/tmp/code, execs entrypoint
Rootfs Images
Pre-built ext4 root filesystems built in-cluster via ArgoCD PostSync hook:
| Image | Size | Contents |
|---|---|---|
alpine-minimal | 32 MB | Alpine + busybox |
alpine-python | 128 MB | Alpine + Python 3.12 |
alpine-node | 128 MB | Alpine + Node.js (rebuilt when Alpine’s nodejs changes) |
Kubernetes Resources
All manifests in kube/firecracker/manifests/:
- Deployment —
firecracker-ctlwith/dev/kvmdevice plugin,kvm=truenode selector - Service — ClusterIP on port 9001
- PVC — 2Gi Longhorn volume for rootfs + vmlinux kernel
- NetworkPolicy — Ingress from edge functions, the dashboard proxy and kbve-workflows only
- KEDA ScaledObject — minReplicas=1, cron scales to 2 during peak hours
- Rootfs Init Job — ArgoCD PostSync hook, builds ext4 images in-cluster
Trust levels
Two ecosystems
Two Ecosystems
Firecracker runs in two parallel deployments in the same namespace, chosen by trust level:
| Deployment | Network | Access | Use Case |
|---|---|---|---|
firecracker-ctl | None (MMDS only) | Edge functions, dashboard, workflows | Ephemeral, untrusted code execution |
firecracker-ctl-direct | Direct, pod eth0 | Dashboard only (staff) | Persistent endpoints with outbound internet |
firecracker-ctl-net | Gluetun/WireGuard VPN | Dashboard only (staff) | Parked (replicas: 0) |
firecracker-ctl-direct masquerades VM traffic out the pod’s own eth0 (FC_TUNNEL_IFACE=eth0). It serves behind the firecracker-ctl-net Service, which callers address by name; point the selector back at app: firecracker-ctl-net to restore the VPN ecosystem.
firecracker-ctl-net shares its network namespace with a Gluetun sidecar, so VM traffic exits through a WireGuard tunnel. It is parked until it has a Proton key of its own: the current one is shared with another consumer and the tunnel drops every few minutes.
In both, firecracker-ctl rejects any FORWARDed VM packet bound for 10/8, 172.16/12, 192.168/16, 169.254/16, 100.64/10 or 127/8 (only VM ↔ VM inside the pool is let through), and the direct pod’s NetworkPolicy allows egress to 0.0.0.0/0 minus the same private ranges. Guests reach the internet, never the cluster.
Named long-lived VMs
Persistent endpoints (/fc/*)
Persistent Endpoints (/fc/*)
Long-lived VMs that expose HTTP servers, reached by name. Think Fly.io Machines or Cloud Run — deploy once, stays up until explicitly stopped. Lives in the networked ecosystem only.
Request Flow
Staff dashboard → kbve.com/dashboard/firecracker-net/proxy/* → dashboard-proxy (staff session check) → firecracker-ctl-net.firecracker.svc:9001/{fc,proxy}/... → VM tap IP:{http_port}/{*path} → responseTwo hops of reverse proxy: dashboard-proxy authenticates and scopes to staff, firecracker-ctl does name→VM lookup and forwards over TAP. An endpoint deployed with visibility: "public" is also served on /public-proxy/{name}/*; a staff-only one answers 403 there.
API Additions (networked deployments only)
| Method | Path | Description |
|---|---|---|
POST | /fc/deploy | Deploy a persistent VM with a unique name + http_port |
GET | /fc/list | List all persistent endpoints with status |
GET | /fc/{name} | Get a single endpoint’s metadata + health |
DELETE | /fc/{name} | Stop and destroy a persistent endpoint |
GET | /fc/{name}/logs | The VM’s stdout/stderr ring (up to 256 KiB) |
ANY | /proxy/{name}/{*path} | Reverse-proxy HTTP into the named VM |
ANY | /public-proxy/{name}/{*path} | Same, only for endpoints deployed public |
Deploy payload includes rootfs image, entrypoint, optional code blob (raw drive), env vars (via MMDS), http_port, vcpu/memory and visibility. No timeout field — persistent VMs live until DELETE.
Networking (TAP per VM)
Persistent endpoints require TAP networking (deferred in Phase 1 for ephemeral VMs — MMDS was enough for outbound-only workloads). Inbound HTTP to a specific guest IP:port is not reachable via MMDS.
- Each persistent VM gets a
/dev/net/tunTAP device inside the pod netns - A private /30 per VM out of
172.18.0.0/16(host .1, guest .2) - firecracker-ctl maintains
name → tap_ip:http_portmap for the proxy - Guest gets the IP via kernel
ip=boot args; no DHCP needed - VM egress is masqueraded out
FC_TUNNEL_IFACE:eth0on the direct pod, the WireGuard tunnel on the VPN pod
Lifecycle
- Deploy → allocate TAP + IP, boot VM, wait for
GET http://{tap_ip}:{http_port}/health(configurable path), mark healthy - Unhealthy → three failed probes mark
degraded; the next 2xx recovers it; proxy still forwards; restart is manual - Delete → SIGTERM the VMM process, release TAP + IP, remove from map
- Pod restart → all persistent endpoints lost (in-memory state only).
Rootfs Requirements
A persistent-VM rootfs must:
- Boot with
ip=...::::eth0:offkernel args (kernel-side config, no DHCP) - Run an HTTP server on the declared
http_portas PID 1 (or via a wrapper that re-execs entrypoint) - Respond to
GET /healthwith200when ready
Web rootfs images built for this: alpine-python-web (Python + FastAPI shim) and alpine-node-web (services/firecracker/rootfs/node-web, Node + Fastify), each staged into the cluster by its own rootfs-stage Job.
Security
- The control routes are staff-gated at dashboard-proxy (DASHBOARD_VIEW to read, DASHBOARD_MANAGE to change)
- VMs cannot reach each other — Firecracker jailer isolates per-VM netns; TAP devices sit on a bridge with inter-guest traffic dropped
- VMs cannot reach cluster services — FORWARD rules drop private ranges and the NetworkPolicy denies cluster egress from the pod
Delivery so far
- Shipped — IP allocator (
/30slots from172.18.0.0/16), TAP manager with pod-level NAT/FORWARD rules, the/fc/*registry, the/proxyand/public-proxyforwarders, VM spawn withip=boot args and thepending → starting → healthy/degradedhealth loop, per-VM log capture, and the node-web rootfs.FC_PERSISTENT_ENDPOINTS_ENABLEDkeeps persistent state off the untrusted deployment. - Not yet — on-disk state with automatic redeploy after a pod restart, and per-endpoint quotas.
Questions
Frequently asked
What does Firecracker CTL do?
It is a Rust Axum REST API that manages Firecracker microVMs — creating, polling, and destroying them — with per-VM timeout enforcement and in-memory state tracking via DashMap.
How is user code executed inside a VM?
Code arrives via env.CODE, is written to a padded raw block attached as a second drive (/dev/vdb), and the VM init reads it, writes /tmp/code, and execs the entrypoint passed through boot_args.
What are persistent endpoints?
Long-lived VMs in the networked deployments that expose HTTP servers over per-VM TAP networking, reached by name through the proxy routes and living until explicitly deleted.
Discuss on the forum
Questions, fixes and notes on this page live in the KBVE forum.