docs/how-to/how-to-load-kernel-modules-with-kata.md
This document describes how to load kernel modules inside Kata Containers guest VM.
The kernel modules feature allows you to load specific kernel modules into the guest VM kernel when a sandbox is created. This is useful when your containerized applications require specific kernel functionality that is not built into the guest kernel.
How it works:
modprobe(8), which automatically resolves module dependenciesFailure conditions:
The sandbox will fail to start if:
modprobe(8) is not installed in the guest, or it fails to load the moduleNote: Use this method when you need the kernel modules loaded for all containers. For per-pod configuration, use annotations instead.
The kernel_modules option accepts a list of kernel modules with their parameters. Each list element specifies a module name followed by space-separated parameters.
For runtime-go (configuration-qemu.toml, etc.):
[agent.kata]
kernel_modules = ["e1000e InterruptThrottleRate=3000,3000,3000 EEE=1", "i915"]
For runtime-rs (configuration-qemu-runtime-rs.toml, etc.):
[agent.kata]
kernel_modules = ["e1000e InterruptThrottleRate=3000,3000,3000 EEE=1", "i915"]
The following example loads two modules:
e1000e with parameters InterruptThrottleRate=3000,3000,3000 and EEE=1i915 with no parameterskernel_modules = ["e1000e InterruptThrottleRate=3000,3000,3000 EEE=1", "i915"]
Annotations provide a way to specify kernel modules per pod, which is more flexible than the configuration file approach.
io.katacontainers.config.agent.kernel_modules
The annotation value uses semicolon (;) as the separator between modules. Each module specification consists of:
Example: "e1000e EEE=1; i915 enable_ppgtt=0"
The following example creates two pods, where only pod1 will have the kernel modules e1000e and i915 loaded:
apiVersion: v1
kind: Pod
metadata:
name: pod1
annotations:
io.katacontainers.config.agent.kernel_modules: "e1000e EEE=1; i915"
spec:
runtimeClassName: kata
containers:
- name: c1
image: busybox
command:
- sh
stdin: true
tty: true
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
spec:
runtimeClassName: kata
containers:
- name: c2
image: busybox
command:
- sh
stdin: true
tty: true
Note: To pass annotations to Kata containers, CRI-O must be configured correctly
Configuration File / Annotation
│
▼
SandboxConfig.AgentConfig.KernelModules
│
▼
Converted to gRPC KernelModule messages
│
▼
CreateSandboxRequest sent to Agent
│
▼
Agent executes modprobe in guest VM
runtime-go:
src/runtime/pkg/katautils/config.gosrc/runtime/pkg/oci/utils.go (addAgentConfigOverrides())src/runtime/virtcontainers/kata_agent.go (setupKernelModules())runtime-rs:
src/libs/kata-types/src/config/agent.rssrc/libs/kata-types/src/annotations/mod.rs (update_config_by_annotation())src/runtime-rs/crates/agent/src/types.rs (KernelModule::set_kernel_modules())To verify kernel modules are loaded in the guest VM:
# Inside the container, run:
lsmod | grep <module_name>
# Or check modprobe output in guest VM journal
If module loading fails, check:
/lib/modules/$(uname -r))