docs/how-to/how-to-use-virtio-fs-nydus-with-kata.md
Nydus is a container image acceleration service that provides fast container startup and on-demand data loading. Kata Containers integrates with Nydus through virtio-fs, supporting two operational modes:
Standalone Mode (virtio-fs-nydus)
Inline Mode (inline-virtio-fs) / Builtin Nydus
Refer to kata-nydus-design for detailed design documentation.
┌─────────────────────────────────────────────────────────┐
│ Host System │
│ ┌──────────────┐ ┌──────────────────────┐ │
│ │ nydusd │◄────────┤ nydus-snapshotter │ │
│ │ (standalone)│ │ │ │
│ └──────┬───────┘ └──────────────────────┘ │
│ │ virtiofs │
│ ▼ │
│ ┌──────────────┐ │
│ │ QEMU │ │
│ │ / Cloud-Hypervisor │
│ └──────────────┘ │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Guest VM │
│ ┌──────────────────────────────────────────────┐ │
│ │ /run/kata-containers/shared/ │ │
│ │ ├── containers/<cid>/rootfs (overlay) │ │
│ │ │ ├── upperdir │ │
│ │ │ ├── workdir │ │
│ │ │ └── lowerdir (from rafs) │ │
│ │ └── rafs/<cid>/lowerdir (nydus image) │ │
│ └──────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Host System │
│ ┌──────────────────────────────────────────────┐ │
│ │ nydus-snapshotter │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Dragonball VMM │ │
│ │ ┌────────────────────────────────────────┐ │ │
│ │ │ Builtin Nydusd (virtiofs server) │ │ │
│ │ │ ┌──────────────────────────────────┐ │ │ │
│ │ │ │ Vfs (Virtual File System) │ │ │ │
│ │ │ │ ├── Rafs (nydus image backend) │ │ │ │
│ │ │ │ └── PassthroughFs │ │ │ │
│ │ │ └──────────────────────────────────┘ │ │ │
│ │ └────────────────────────────────────────┘ │ │
│ └──────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Guest VM │
│ ┌──────────────────────────────────────────────┐ │
│ │ /run/kata-containers/shared/containers/ │ │
│ │ ├── <cid>/rootfs (overlay mount) │ │
│ │ ├── <cid>/rootfs_lower/ (Rafs mount) │ │
│ │ └── <cid>/snapshotdir/ │ │
│ │ ├── fs/ (upperdir) │ │
│ │ └── work/ (workdir) │ │
│ │ │ │
│ │ Guest Kernel Overlay Assembly: │ │
│ │ overlay lowerdir=rootfs_lower/ │ │
│ │ upperdir=snapshotdir/fs/ │ │
│ │ workdir=snapshotdir/work/ │ │
│ └──────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
nydusd: The nydus daemon that provides:
nydus-snapshotter: Containerd snapshotter that:
Builtin Nydus (Inline Mode): Integrated nydus in Dragonball VMM:
Use the nydus latest branch and build nydusd:
git clone https://github.com/dragonflyoss/image-service.git
cd image-service
make nydusd
Deploy nydus environment as described in Nydus Setup for Containerd Environment.
Start nydus-snapshotter with enable_nydus_overlayfs enabled:
./nydus-snapshotter --enable-nydus-overlayfs
Use kata-containers latest branch to compile and build kata-containers.img.
Kata Containers supports the following shared filesystem types:
| Type | Description | Hypervisor |
|---|---|---|
virtio-fs | Standard virtio-fs with virtiofsd | QEMU, Cloud-Hypervisor |
virtio-fs-nydus | Virtio-fs with standalone nydusd | QEMU, Cloud-Hypervisor |
inline-virtio-fs | Inline virtio-fs with builtin nydus | Dragonball |
none | Disable shared filesystem | All |
Update configuration-qemu.toml (for the go runtime) or configuration-qemu-runtime-rs.toml (for runtime-rs):
# Enable virtio-fs-nydus for standalone mode
shared_fs = "virtio-fs-nydus"
# Path to nydusd binary (required for virtio-fs-nydus)
virtio_fs_daemon = "/usr/local/bin/nydusd"
# Optional: Extra arguments for nydusd
# Example: virtio_fs_extra_args = ["--log-level", "debug", "--threads", "4"]
virtio_fs_extra_args = []
# Cache mode for virtio-fs (never, auto, always)
virtio_fs_cache = "never"
# Optional: Enable DAX for better performance
virtio_fs_is_dax = false
Update configuration-clh.toml (for the go runtime) or configuration-clh-runtime-rs.toml (for runtime-rs):
shared_fs = "virtio-fs-nydus"
virtio_fs_daemon = "/usr/local/bin/nydusd"
virtio_fs_extra_args = []
virtio_fs_cache = "never"
For Dragonball VMM, use inline mode (builtin nydus), update configuration-dragonball.toml:
shared_fs = "inline-virtio-fs"
# Note: virtio_fs_daemon is not needed for inline mode
# nydusd is built into Dragonball VMM
virtio_fs_cache = "never"
When using virtio-fs-nydus, Kata runtime starts nydusd with the following parameters:
nydusd virtiofs \
--hybrid-mode \
--log-level info \
--apisock /path/to/nydusd-api.sock \
--sock /path/to/virtiofs.sock
Key features:
After nydusd starts, Kata runtime automatically:
/containers within the nydusd virtiofs namespace
/run/kata-containers/shared/containers/ in the guestWhen using inline-virtio-fs with Dragonball:
/run/kata-containers/shared/ # virtiofs mount point
├── containers/<container-id>/ # passthrough_fs from host
│ ├── rootfs/ # container rootfs mount point
│ └── snapshotdir/ # snapshot directory
│ ├── fs/ # upperdir (writable layer)
│ └── work/ # workdir (overlay work directory)
└── rafs/<container-id>/lowerdir/ # Rafs mount (nydus image)
/run/kata-containers/shared/containers/
├── <container-id>/
│ ├── rootfs/ # container rootfs mount point
│ ├── rootfs_lower/ # Rafs mount (lowerdir)
│ └── snapshotdir/
│ ├── fs/ # upperdir
│ └── work/ # workdir
└── passthrough/ # passthrough filesystem
The nydus snapshotter provides the RAFS bootstrap path, nydus config, and snapshot directory through the container rootfs mount options. Runtime-rs passes the RAFS source/config to nydusd, then asks kata-agent to assemble the writable overlay in the guest kernel with:
The nydusd mount request only mounts RAFS:
{
"fs_type": "rafs",
"source": "/path/to/bootstrap",
"config": "{...nydus config...}"
}
Runtime-rs then sends an overlay Storage to kata-agent whose lowerdir points
at /run/kata-containers/shared/rafs/<cid>/lowerdir and whose upper/work dirs
come from /run/kata-containers/shared/containers/<cid>/snapshotdir/.
The guest kernel assembles overlay filesystem:
$sudo nerdctl run --snapshotter nydus --runtime io.containerd.kata.v2 --net=none --rm -it ghcr.io/dragonflyoss/image-service/ubuntu:nydus-nightly-v5 lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
pmem0 259:0 0 254M 1 disk
`-pmem0p1 259:1 0 253M 1 part
Create a Pod specification:
apiVersion: v1
kind: Pod
metadata:
name: nydus-test
annotations:
io.containerd.osfeature: "nydus.remoteimage.v1"
spec:
runtimeClassName: kata
containers:
- name: test
image: ghcr.io/dragonflyoss/image-service/ubuntu:nydus-nightly-v5
command: ["/bin/sleep", "600"]
You can pass additional arguments to nydusd through configuration:
virtio_fs_extra_args = ["--log-level", "debug", "--threads", "4"]
Enable prefetch for faster container startup:
# Path to prefetch file list
prefetch_list_path = "/path/to/prefetch_file.list"
Choose appropriate cache mode based on your use case:
virtio_fs_cache = "auto"
Enable DAX for memory-mapped I/O:
virtio_fs_is_dax = true
virtio_fs_cache_size = 1024 # Size in MiB
Enable debug logging for nydusd:
virtio_fs_extra_args = ["--log-level", "debug"]
Or via annotation:
annotations:
io.katacontainers.config.hypervisor.virtio_fs_extra_args: "--log-level=debug"
| Component | Host Path | Guest Path | Notes |
|---|---|---|---|
| Virtiofs mount | N/A | /run/kata-containers/shared/ | Root virtiofs mount point |
| Passthrough FS | /run/kata-containers/shared/sandboxes/<sid>/rw/ | /run/kata-containers/shared/containers/ | Mounted at /containers in nydusd namespace |
| Rafs mount | Bootstrap path from snapshotter | /run/kata-containers/shared/rafs/<cid>/lowerdir | Mounted via nydusd API |
| Container rootfs | /run/kata-containers/shared/sandboxes/<sid>/rw/<cid>/rootfs | /run/kata-containers/shared/containers/<cid>/rootfs | Overlay mount point |
| Snapshot dir | From snapshotter | /run/kata-containers/shared/containers/<cid>/snapshotdir/ | Contains upperdir and workdir |
| Component | Host Path | Guest Path | Notes |
|---|---|---|---|
| Virtiofs mount | N/A | /run/kata-containers/shared/containers/ | Root virtiofs mount point |
| Passthrough FS | /run/kata-containers/shared/sandboxes/<sid>/rw/passthrough/ | /run/kata-containers/shared/containers/passthrough/ | Uses PASSTHROUGH_FS_DIR |
| Rafs mount | Bootstrap path from snapshotter | /run/kata-containers/shared/containers/<cid>/rootfs_lower/ | Mounted via DeviceManager |
| Container rootfs | /run/kata-containers/shared/sandboxes/<sid>/rw/passthrough/<cid>/rootfs | /run/kata-containers/shared/containers/<cid>/rootfs | Overlay mount point |
| Feature | Standalone (virtio-fs-nydus) | Inline (inline-virtio-fs) |
|---|---|---|
| Hypervisor | QEMU, Cloud-Hypervisor | Dragonball |
| Nydusd Process | Independent process | Built into VMM |
| Overlay Support | Guest kernel | Guest kernel |
| Performance | Good | Good |
| Resource Usage | Higher (separate process) | Lower (integrated) |
| Flexibility | More configurable | Less configurable |
| Use Case | General purpose | Lightweight VMs |
| Startup Time | Slower (daemon startup) | Faster (no daemon) |
| Memory Overhead | Higher | Lower |