在Linux中安装containerd作为kubernetes的容器运行时
概述
从kubernetes1.24开始的版本移除了内置的docker支持,用户可以自行选择需要使用的容器运行时,比如containerd、CRI-O、Docker Engine等等,这里我们采用二进制安装的方式使用containerd作为kubernetes的容器运行时
操作环境
操作系统
CentOS 7.9
containerd版本
v1.6.19
安装步骤
下载containerd、runc、cni-plugins
mkdir -p /workspace/containerd
cd /workspace/containerd
wget https://github.com/containerd/containerd/releases/download/v1.6.19/containerd-1.6.19-linux-amd64.tar.gz
wget https://github.com/containerd/nerdctl/releases/download/v1.2.1/nerdctl-1.2.1-linux-amd64.tar.gz
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
wget https://github.com/opencontainers/runc/releases/download/v1.1.4/runc.amd64
wget https://github.com/containernetworking/plugins/releases/download/v1.2.0/cni-plugins-linux-amd64-v1.2.0.tgz
解压安装上述软件
tar Cxzvf /usr/local containerd-1.6.19-linux-amd64.tar.gz
tar Cxzvvf /usr/local/bin nerdctl-1.2.1-linux-amd64.tar.gz
mkdir -p /usr/local/lib/systemd/system
cp containerd.service /usr/local/lib/systemd/system/containerd.service
systemctl daemon-reload
systemctl enable --now containerd
install -m 755 runc.amd64 /usr/local/sbin/runc
mkdir -p /opt/cni/bin
tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.2.0.tgz
生成默认配置文件
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
修改默认配置
编辑生成好的默认配置文件
vim /etc/containerd/config.toml
将配置文件中SystemdCgroup
的值修改为true
,即SystemdCgroup = true
如下所示
[ plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options ]
SystemdCgroup = false
修改pause镜像源,将registry.k8s.io/pause:3.6
修改为registry.aliyuncs.com/google_containers/pause:3.6
[plugins."io.containerd.grpc.v1.cri"]
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.6"
重启containerd,安装就完成了
systemctl restart containerd
使用示例
拉取镜像到指定的命名空间
ctr -n k8s.io image pull registry.aliyuncs.com/google_containers/pause:3.6
重命名标签
ctr -n k8s.io i tag registry.aliyuncs.com/google_containers/pause:3.6 registry.k8s.io/pause:3.6
查看所有命名空间
ctr namespaces ls
查看指定命名空间的镜像
ctr --n k8s.io image ls
作者: 陌上荼靡