容器运行时 笔记 / CRI-O / CRI-O 安装说明

目录、参考文献


CRI-O 是一个基于开放容器计划(Open Container Initiative (OCI))的 Kubernetes 容器运行时接口(Kubernetes Container Runtime Interface (CRI))

本文的环境为 Linux 操作系统

1 安装 CRI-O 的打包版本

CRI-O 用 openSUSE 的 OBS 为本地包管理器构建

1.1 支持的版本

CRI-O 遵循 Kubernetes 的 3 个次要版本的支持周期
CRI-O 还尝试为以下操作系统打包:

Fedora 31+
openSUSE
CentOS 8
CentOS 8 Stream
CentOS 7
Debian Unstable
Debian Testing
Debian 10
Debian 11
Rasbian 10
xUbuntu 22.04
xUbuntu 21.10
xUbuntu 20.04
xUbuntu 18.04

要安装 CRI-O,请为操作系统选择支持的版本
然后将其导出为变量(供后边的命令使用),如:export VERSION=1.19

发行版还被保存为子项目
例如想使用 1.19.1,可以设置:export VERSION=1.19:1.19.1

1.2 安装说明

1.2.1 openSUSE

sudo zypper install cri-o

1.2.2 Fedora 31 或更新的版本

sudo dnf module enable cri-o:$VERSION
sudo dnf install cri-o

对于 Fedora,只支持设置次版本,即:VERSION=1.18,不支持设置补丁版本:VERSION=1.18.3

注意:从 1.24.0 开始,cri-o 包不再依赖 containernetworking-plugins
删除此依赖项允许用户在不删除文件的情况下就能安装自己的 CNI 插件
如果想要使用以前提供的那些 CNI 插件,还应运行:

sudo dnf install containernetworking-plugins

1.2.3 其它基于 yum 的操作系统

要安装在以下操作系统上,请将环境变量 $OS 设置为下表中对应的值:

操作系统$OS
Centos 8CentOS_8
Centos 8 StreamCentOS_8_Stream
Centos 7CentOS_7

然后以 root 身份运行:

sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/devel:kubic:libcontainers:stable.repo
sudo curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo
sudo yum install cri-o -y

注意:从 1.24.0 开始,cri-o 包不再依赖 containernetworking-plugins
删除此依赖项允许用户在不删除文件的情况下就能安装自己的 CNI 插件
如果想要使用以前提供的那些 CNI 插件,还应运行:

yum install containernetworking-plugins

1.2.4 基于 APT 的操作系统

注意:请先安装 curlgnupg

要安装在下边表格中的操作系统上,则请先将环境变量 $OS 设置为下表中对应的值:

操作系统$OS
Debian UnstableDebian_Unstable
Debian TestingDebian_Testing
Debian 10Debian_10
Raspberry Pi OSRaspbian_10
Ubuntu 22.04xUbuntu_22.04
Ubuntu 21.10xUbuntu_21.10
Ubuntu 20.04xUbuntu_20.04
Ubuntu 18.04xUbuntu_18.04

如果安装 cri-o-runc(推荐),则需要安装 libseccomp >= 2.4.1

注意:这在基于 Debian 10(buster)或更低版本的发行版中不可用
因此需要启用 buster 反向移植:

echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list
apt update
apt install -y -t buster-backports libseccomp2 || apt update -y -t buster-backports libseccomp2

然后以 root 身份运行:

echo "deb [signed-by=/usr/share/keyrings/libcontainers-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
echo "deb [signed-by=/usr/share/keyrings/libcontainers-crio-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list

mkdir -p /usr/share/keyrings
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | gpg --dearmor -o /usr/share/keyrings/libcontainers-archive-keyring.gpg
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/Release.key | gpg --dearmor -o /usr/share/keyrings/libcontainers-crio-archive-keyring.gpg

apt-get update
apt-get install cri-o cri-o-runc

注意:我们包含 cri-o-runc,是因为 Ubuntu 和 Debian 包含它们自己的打包版本的 runc
虽然这个版本应该也可以与 CRI-O 一起使用
但保持 CRI-O 与 runc 的打包版本同步可以确保它们能够一起工作
如果想使用操作系统发行版的 runc,则需要添加文件:

[crio.runtime.runtimes.runc]
runtime_path = ""
runtime_type = "oci"
runtime_root = "/run/runc"

/etc/crio/crio.conf.d/ 目录

注意:从 1.24.0 开始,cri-o 包不再依赖 containernetworking-plugins
删除此依赖项允许用户在不删除文件的情况下就能安装自己的 CNI 插件
如果想要使用以前提供的那些 CNI 插件,还应运行:

apt-get install containernetworking-plugins

2 用源码构建和安装 CRI-O

2.1 运行时依赖

  • runc,清除容器运行时或任何其它兼容 OCI 的运行时
  • iproute
  • iptables

预期会安装最新版本的 runc,CRI-O 会将其选为默认运行时

2.2 构建和运行依赖

2.2.1 Fedora -RHEL 7 - CentOS

需要:Fedora、RHEL 7、CentOS 与相关的软件:

yum install -y \
  containers-common \
  device-mapper-devel \
  git \
  glib2-devel \
  glibc-devel \
  glibc-static \
  go \
  gpgme-devel \
  libassuan-devel \
  libgpg-error-devel \
  libseccomp-devel \
  libselinux-devel \
  pkgconfig \
  make \
  runc

请注意:

2.2.2 RHEL 8

请确保已订阅了下边的仓库:
BaseOS/x86_64
Appstream/x86_64 CodeReady Linux Builder for x86_64

subscription-manager repos --enable=rhel-8-for-x86_64-baseos-rpms
subscription-manager repos --enable=rhel-8-for-x86_64-appstream-rpms
subscription-manager repos --enable=codeready-builder-for-rhel-8-x86_64-rpms

如果没有订阅,请根据下边的指南进行订阅:
https://access.redhat.com/solutions/265523

这需要 1.12 或更改版本的 go

yum module -y install go-toolset
yum install -y \
  containers-common \
  device-mapper-devel \
  git \
  make \
  glib2-devel \
  glibc-devel \
  glibc-static \
  runc \

如何在 RHEL 上安装一个源 rpm:
https://www.itechlounge.net/2012/12/linux-how-to-install-source-rpm-on-rhelcentos/

依赖:gpgme-devel
http://download.eng.bos.redhat.com/brewroot/packages/gpgme/1.10.0/6.el8/x86_64/

依赖:go-md2man:

go get github.com/cpuguy83/go-md2man

以下依赖:

libassuan \
libassuan-devel \
libgpg-error \
libseccomp \
libselinux \
pkgconf-pkg-config \

2.2.3 Debian - RASPBIAN -Ubuntu

在 Debian、Raspbian 和 Ubuntu 发行版上
启用 Kubic 项目仓库(用于 containers-commoncri-o-runc 软件包)并安装以下软件包:

Debian 到 buster 版本之前 - Raspbian - Ubuntu 到 18.04 版本之前

apt update -qq && \
# For Debian 10(buster) or below: use "apt install -t buster-backports"
apt install -y  \
  btrfs-tools \
  containers-common \
  git \
  golang-go \
  libassuan-dev \
  libdevmapper-dev \
  libglib2.0-dev \
  libc6-dev \
  libgpgme11-dev \
  libgpg-error-dev \
  libseccomp-dev \
  libsystemd-dev \
  libbtrfs-dev \
  libselinux1-dev \
  pkg-config \
  go-md2man \
  cri-o-runc \
  libudev-dev \
  software-properties-common \
  gcc \
  make

Debian bullseye 或更高版本 - Ubuntu 20.04 或更高版本

apt-get update -qq && apt-get install -y \
  libbtrfs-dev \
  containers-common \
  git \
  golang-go \
  libassuan-dev \
  libdevmapper-dev \
  libglib2.0-dev \
  libc6-dev \
  libgpgme-dev \
  libgpg-error-dev \
  libseccomp-dev \
  libsystemd-dev \
  libselinux1-dev \
  pkg-config \
  go-md2man \
  cri-o-runc \
  libudev-dev \
  software-properties-common \
  gcc \
  make

注意:

如果使用比较旧的版本或长期支持版本
请检查 runc 版本是否足够新(运行 runc --version 生成 spec: 1.0.0
否则应该自己构建

检查 golang 的版本是否足够新,需要 1.12.x 或更高版本
如果需要,可以在官方下载网站上获得更新的 golang 版本

2.3 获取源代码

克隆源代码:

git clone https://github.com/cri-o/cri-o # or your fork
cd cri-o

确保 ORI-Okubernetes 的主版本号匹配

2.4 构建

要使用默认构建标签,则用 seccomp 进行安装:

make
sudo make install

如果不构建具有 seccomp 支持的 CRI-O,可在运行 make 时添加 BUILDTAGS=""

make BUILDTAGS=""
sudo make install

2.4.1 用 Ansible 安装

可以用 Ansible 角色来自动执行上述步骤:

sudo su -
mkdir -p ~/.ansible/roles
cd ~/.ansible/roles
git clone https://github.com/alvistack/ansible-role-cri_o.git cri_o
cd ~/.ansible/roles/cri_o
pip3 install --upgrade --ignore-installed --requirement requirements.txt
molecule converge
molecule verify

2.4.2 构建标签

CRI-O 支持可选的构建标签来编译对各种特性的支持
要为 make 选项添加构建标签,需要设置 BUILDTAGS 变量

make BUILDTAGS='seccomp apparmor'
构建标签特性依赖
seccomp系统调用过滤libseccomp
selinuxselinux 进程与挂载标签libselinux
apparmorapparmor 配置文件支持

CRI-O 使用 containers/image 管理镜像,使用以下构建标签

构建标签特性依赖
containers_image_openpgp使用 native golang pgp 代替 cgo
containers_image_ostree_stub禁止将 ostree 用于图像传输

CRI-O 还使用 containers/storage 来管理容器存储

构建标签特性依赖
exclude_graphdriver_btrfs将 btrfs 排除在存储选项之外
btrfs_noversion用于构建 < 3.16.1 的 btrfs 版本btrfs
exclude_graphdriver_devicemapper将 devicemapper 排除在存储选项之外
libdm_no_deferred_remove不要使用 devicemapper 编译 deferred removedevicemapper
exclude_graphdriver_overlay将 overlay 排除在存储选项之外
ostree用 ostree 构建存储ostree

2.5 静态构建

可以用官方提供的 nix 包及其在这个仓库中的衍生物来构建 CRI-O 的静态链接二进制文件
这些构建是可重现的,并将为 glibc 创建一个剥离 x86_64/amd64aarch64/arm64 的 ELF 二进制文件
这些二进制文件也经过集成测试并支持以下特性:

  • apparmor
  • btrfs
  • device mapper
  • gpgme
  • seccomp
  • selinux

要在本地构建二进制文件,要么安装 nix 包管理器
要么使用 make build-static 目标,它依赖于 nixos/nix 容器镜像

整个构建过程可能会占用大量的 CPU 时间,具体时间取决于使用的硬件
生成的二进制文件应该在 bin/static/crio

要在没有任何现成容器的情况下并通过安装的 nix 包管理器构建二进制文件
只需在此仓库的根目录中运行以下命令:

nix build -f nix

生成的二进制文件应该在 result/bin
要构建二进制的 arm 变体,只需运行:

nix build -f nix/default-arm64.nix

2.5.1 创建一个发行存档

发布包包含所有静态二进制文件、手册页和配置文件,如 00-default.conf
release-bundle 目标可用于在当前仓库中构建新的发布存档:

make release-bundle
…
Created ./bundle/cri-o.amd64.v1.20.0.tar.gz

2.6 下载 conmon

conmonCRI-O 用于监视容器日志和退出信息的守护程序,每个容器各一个

运行下边的命令下载 conmon 到 $PATH

git clone https://github.com/containers/conmon
cd conmon
make
sudo make install

2.7 设置 CNI 网络

contrib/cni README 中提供了设置 CNI 网络的描述
要点是需要启用一些基本的网络配置并在系统上安装 CNI 插件

2.8 CRI-O 配置

如果是第一次安装,请使用以下命令生成和安装配置文件:

sudo make install.config

2.8.1 验证 registries.conf 中的注册表

编辑 /etc/containers/registries.conf 并验证 registry 选项中是否包含有效值,如:

[registries.search]
registries = ['registry.access.redhat.com', 'registry.fedoraproject.org', 'quay.io', 'docker.io']

[registries.insecure]
registries = []

[registries.block]
registries = []

有关此文件的更多信息,请参阅 registry.conf(5)

2.8.2 可选的 - 修改日志级别

用户可以通过指定像 /etc/crio/crio.conf.d/01-log-level.conf 这样的覆盖来修改 log_level
从而更改日志级别
可选项:fatal、panic、error、warn、info (default)、debug、trace

[crio.runtime]
log_level = "info"

2.8.3 可选的 - 修改 capabilities 与 sysctls

CRI-O 默认使用以下能力:

default_capabilities = [
	"CHOWN",
	"DAC_OVERRIDE",
	"FSETID",
	"FOWNER",
	"SETGID",
	"SETUID",
	"SETPCAP",
	"NET_BIND_SERVICE",
	"KILL",
]

并且默认没有设置 sysctls

default_sysctls = [
]

用户可以通过向 /etc/crio/crio.conf.d 添加覆盖来更改任一默认值

2.9 启动 CRI-O

运行 make install 会将 CRI-O 下载到目录:

/usr/local/bin/crio

可以在该目录手动运行它,或者也可以设置一个 systemd 单元文件:

sudo make install.systemd

systemd 负责运行 CRI-O:

sudo systemctl daemon-reload
sudo systemctl enable crio
sudo systemctl start crio

2.10 使用 CRI-O

按照教程快速开始运行简单的 pod 和容器

运行一个完整的集群见说明

用 kubeadm 运行,见 kubeadm 说明

2.11 更新 CRI-O

2.11.1 openSUSE

sudo zypper update
sudo zypper update cri-o

2.11.2 Fedora 31 or later

sudo dnf update
sudo dnf update cri-o

2.11.3 其它基于 yum 的操作系统

sudo yum update
sudo yum update cri-o

2.11.4 基于 APT 的操作系统

如果更新到补丁版本(如 VERSION=1.8.3 ),运行:

apt update cri-o cri-o-runc

否则,请确保将环境变量 $OS 设置为下表中与操作系统对应的字段:

操作系统$OS
Debian UnstableDebian_Unstable
Debian TestingDebian_Testing
Ubuntu 20.04xUbuntu_20.04
Ubuntu 19.10xUbuntu_19.10
Ubuntu 19.04xUbuntu_19.04
Ubuntu 18.04xUbuntu_18.04

要升级,请为操作系统选择支持的版本,并将其导出为变量:export VERSION=1.18
然后以 root 身份运行以下命令:

sudo rm /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list

sudo echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list

sudo curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key | apt-key add -

sudo apt update
sudo apt install cri-o cri-o-runc

目录、参考文献

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值