CRI-O
CRI-O 是 OCI 规范的 Kubernetes 容器运行时接口实现。因此,它是可以与 Kubernetes 集群节点一起使用的容器运行时之一。
安装
该软件包将设置系统以加载 overlay
和 br_netfilter
模块,并设置以下 sysctl 选项
net.bridge.bridge-nf-call-iptables = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.ipv4.ip_forward = 1
要在不重启的情况下使用 CRI-O,请确保 加载 模块并相应地 配置 sysctl 值。
配置
CRI-O 通过 /etc/crio/crio.conf
或 /etc/crio/crio.conf.d/
中的 drop-in 配置文件进行配置。
网络
插件安装
CRI-O 可以利用 cni-plugins 提供的容器网络,或者使用集群内部署(如 weave、flannel、calico 等)安装的插件。
插件目录
Arch 将 cni-plugins 提供的插件安装到 /usr/lib/cni
和 /opt/cni/bin
两个目录,但大多数其他插件(例如集群内部署、kubelet 管理的插件等)默认只安装到第二个目录。CRI-O 仅配置为在第一个目录中查找插件,因此,如果未进行一些配置更改,则第二个目录中的任何插件都不可用。
这可能会表现为网络无法工作,并在 CRI-O 日志中出现类似于以下错误的条目
Error validating CNI config file /etc/cni/net.d/<plugin-config-file>.conf: [failed to find plugin "<plugin>" in path [/usr/lib/cni/]]
有两种解决方案可以解决此问题:要么更改每个其他系统以使用 /usr/lib/cni
,要么更新 CRI-O 以使用后一个目录而不是第一个目录。可以使用 drop-in 配置文件来实现第二种解决方案
/etc/crio/crio.conf.d/00-plugin-dir.conf
[crio.network] plugin_dirs = [ "/opt/cni/bin/", ]
由于这是一个数组,您也可以在此处设置两个或任何其他目录作为可能的插件位置。
插件配置
将 /usr/share/doc/cri-o/examples/cni/
中的示例之一复制到 /etc/cni/net.d
并根据需要进行修改。
存储
默认情况下,CRI-O 使用 overlay
驱动程序作为 /var/lib/containers/storage/
中容器存储的 storage_driver
。但是,也可以通过更改 containers-storage.conf(5) 中的 driver
,将其配置为原生使用 Btrfs 或 ZFS。
/etc/containers/storage.conf
[storage] driver = "btrfs"
运行时
cri-o 软件包依赖于 oci-runtime 虚拟软件包,默认情况下,它使用词典编纂顺序选择 crun 。
但是,CRI-O 默认使用 runc 容器运行时。显式安装 runc 软件包,或通过添加以下 drop-in 配置文件将 crun 配置为容器运行时
/etc/crio/crio.conf.d/01-crun.conf
[crio.runtime] default_runtime = "crun" [crio.runtime.runtimes.crun] runtime_path = "/usr/bin/crun" runtime_type = "oci" runtime_root = "/run/crun"
运行
启动 并 启用 crio.service
systemd 单元。
测试
像这样使用 crio status
# crio status info
cgroup driver: systemd storage driver: overlay storage graph root: /var/lib/containers/storage storage image: default GID mappings (format <container>:<host>:<size>): 0:0:4294967295 default UID mappings (format <container>:<host>:<size>): 0:0:4294967295
和
# crio status config
现在 安装 crictl 软件包,并查看例如 https://kubernetes.ac.cn/docs/tasks/debug-application-cluster/crictl/ 或 https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md,或者简单地
# source <(crictl completion bash)
# crictl pull index.docker.io/busybox # crictl pull quay.io/prometheus/busybox # crictl images
# curl -O https://raw.githubusercontent.com/kubernetes-sigs/cri-tools/master/docs/examples/podsandbox-config.yaml # curl -O https://raw.githubusercontent.com/kubernetes-sigs/cri-tools/master/docs/examples/container-config.yaml # crictl run container-config.yaml podsandbox-config.yaml
# crictl logs $(crictl ps --last 1 --output yaml | yq -r .containers[0].id) # crictl exec -it $(crictl ps --last 1 --output yaml | yq -r .containers[0].id) /bin/sh
# crictl rm -af # crictl rmp -af
请注意 Docker Hub 不是硬编码的,因此请显式指定容器注册表。(另请参阅 https://github.com/kubernetes-sigs/cri-tools/pull/718。)
参见
- CRI-O on Github - Github 上的 CRI-O 仓库
- CRI-O Website - CRI-O 官方网站