c12s-kubespray/docs/containerd.md
Ilya Margolin 5a8cf824f6
[containerd] Simplify limiting number of open files per container (#9319)
by setting a default runtime spec with a patch for RLIMIT_NOFILE.

- Introduces containerd_base_runtime_spec_rlimit_nofile.
- Generates base_runtime_spec on-the-fly, to use the containerd version
  of the node.
2022-11-08 06:44:32 -08:00

3.3 KiB

containerd

containerd An industry-standard container runtime with an emphasis on simplicity, robustness and portability Kubespray supports basic functionality for using containerd as the default container runtime in a cluster.

To use the containerd container runtime set the following variables:

k8s_cluster.yml

When kube_node contains etcd, you define your etcd cluster to be as well schedulable for Kubernetes workloads. Thus containerd and dockerd can not run at same time, must be set to bellow for running etcd cluster with only containerd.

container_manager: containerd

etcd.yml

etcd_deployment_type: host

Containerd config

Example: define registry mirror for docker hub

containerd_registries:
  "docker.io":
    - "https://mirror.gcr.io"
    - "https://registry-1.docker.io"

containerd_registries is ignored for pulling images when image_command_tool=nerdctl (the default for container_manager=containerd). Use crictl instead, it supports containerd_registries but lacks proper multi-arch support (see #8375):

image_command_tool: crictl

Containerd Runtimes

Containerd supports multiple runtime configurations that can be used with RuntimeClass Kubernetes feature. See runtime classes in containerd for the details of containerd configuration.

In kubespray, the default runtime name is "runc", and it can be configured with the containerd_runc_runtime dictionary:

containerd_runc_runtime:
  name: runc
  type: "io.containerd.runc.v2"
  engine: ""
  root: ""
  options:
    systemdCgroup: "false"
    binaryName: /usr/local/bin/my-runc
  base_runtime_spec: cri-base.json

Further runtimes can be configured with containerd_additional_runtimes, which is a list of such dictionaries.

Default runtime can be changed by setting containerd_default_runtime.

Base runtime specs and limiting number of open files

base_runtime_spec key in a runtime dictionary is used to explicitly specify a runtime spec json file. runc runtime has it set to cri-base.json, which is generated with ctr oci spec > /etc/containerd/cri-base.json and updated to include a custom setting for maximum number of file descriptors per container.

You can change maximum number of file descriptors per container for the default runc runtime by setting the containerd_base_runtime_spec_rlimit_nofile variable.

You can tune many more settings by supplying your own file name and content with containerd_base_runtime_specs:

containerd_base_runtime_specs:
  cri-spec-custom.json: |
    {
      "ociVersion": "1.0.2-dev",
      "process": {
        "user": {
          "uid": 0,
    ...    

The files in this dict will be placed in containerd config directory, /etc/containerd by default. The files can then be referenced by filename in a runtime:

containerd_runc_runtime:
  name: runc
  base_runtime_spec: cri-spec-custom.json
  ...