|
| 1 | +# Loading kernel modules |
| 2 | + |
| 3 | +A new feature for loading kernel modules was introduced in Kata Containers 1.9. |
| 4 | +The list of kernel modules and their parameters can be provided using the |
| 5 | +configuration file or OCI annotations. The [Kata runtime][1] gives that |
| 6 | +information to the [Kata Agent][2] through gRPC when the sandbox is created. |
| 7 | +The [Kata Agent][2] will insert the kernel modules using `modprobe(8)`, hence |
| 8 | +modules dependencies are resolved automatically. |
| 9 | + |
| 10 | +The sandbox will not be started when: |
| 11 | + |
| 12 | + * A kernel module is specified and the `modprobe(8)` command is not installed in |
| 13 | + the guest or it fails loading the module. |
| 14 | + * The module is not available in the guest or it doesn't meet the guest kernel |
| 15 | + requirements, like architecture and version. |
| 16 | + |
| 17 | +In the following sections are documented the different ways that exist for |
| 18 | +loading kernel modules in Kata Containers. |
| 19 | + |
| 20 | +- [Using Kata Configuration file](#using-kata-configuration-file) |
| 21 | +- [Using annotations](#using-annotations) |
| 22 | + |
| 23 | +# Using Kata Configuration file |
| 24 | + |
| 25 | +``` |
| 26 | +NOTE: Use this method, only if you need to pass the kernel modules to all |
| 27 | +containers. Please use annotations described below to set per pod annotations. |
| 28 | +``` |
| 29 | + |
| 30 | +The list of kernel modules and parameters can be set in the `kernel_modules` |
| 31 | +option as a coma separated list, where each entry in the list specifies a kernel |
| 32 | +module and its parameters. Each list element comprises one or more space separated |
| 33 | +fields. The first field specifies the module name and subsequent fields specify |
| 34 | +individual parameters for the module. |
| 35 | + |
| 36 | +The following example specifies two modules to load: `e1000e` and `i915`. Two parameters |
| 37 | +are specified for the `e1000` module: `InterruptThrottleRate` (which takes an array |
| 38 | +of integer values) and `EEE` (which requires a single integer value). |
| 39 | + |
| 40 | +```toml |
| 41 | +kernel_modules=["e1000e InterruptThrottleRate=3000,3000,3000 EEE=1", "i915"] |
| 42 | +``` |
| 43 | + |
| 44 | +Not all the container managers allow users provide custom annotations, hence |
| 45 | +this is the only way that Kata Containers provide for loading modules when |
| 46 | +custom annotations are not supported. |
| 47 | + |
| 48 | +There are some limitations with this approach: |
| 49 | + |
| 50 | +* Write access to the Kata configuration file is required. |
| 51 | +* The configuration file must be updated when a new container is created, |
| 52 | + otherwise the same list of modules is used, even if they are not needed in the |
| 53 | + container. |
| 54 | + |
| 55 | +# Using annotations |
| 56 | + |
| 57 | +As was mentioned above, not all containers need the same modules, therefore using |
| 58 | +the configuration file for specifying the list of kernel modules per [POD][3] can |
| 59 | +be a pain. Unlike the configuration file, annotations provide a way to specify |
| 60 | +custom configurations per POD. |
| 61 | + |
| 62 | +The list of kernel modules and parameters can be set using the annotation |
| 63 | +`io.katacontainers.config.agent.kernel_modules` as a semicolon separated |
| 64 | +list, where the first word of each element is considered as the module name and |
| 65 | +the rest as its parameters. |
| 66 | + |
| 67 | +In the following example two PODs are created, but the kernel modules `e1000e` |
| 68 | +and `i915` are inserted only in the POD `pod1`. |
| 69 | + |
| 70 | + |
| 71 | +```yaml |
| 72 | +apiVersion: v1 |
| 73 | +kind: Pod |
| 74 | +metadata: |
| 75 | + name: pod1 |
| 76 | + annotations: |
| 77 | + io.katacontainers.config.agent.kernel_modules: "e1000e EEE=1; i915" |
| 78 | +spec: |
| 79 | + runtimeClassName: kata |
| 80 | + containers: |
| 81 | + - name: c1 |
| 82 | + image: busybox |
| 83 | + command: |
| 84 | + - sh |
| 85 | + stdin: true |
| 86 | + tty: true |
| 87 | + |
| 88 | +--- |
| 89 | +apiVersion: v1 |
| 90 | +kind: Pod |
| 91 | +metadata: |
| 92 | + name: pod2 |
| 93 | +spec: |
| 94 | + runtimeClassName: kata |
| 95 | + containers: |
| 96 | + - name: c2 |
| 97 | + image: busybox |
| 98 | + command: |
| 99 | + - sh |
| 100 | + stdin: true |
| 101 | + tty: true |
| 102 | +``` |
| 103 | +
|
| 104 | +[1]: https://github.com/kata-containers/runtime |
| 105 | +[2]: https://github.com/kata-containers/agent |
| 106 | +[3]: https://kubernetes.io/docs/concepts/workloads/pods/pod/ |
0 commit comments