通过二进制安装Containerd
操作系统为Ubuntu 20.04
,本教程使用官方二进制包进行安装演示。
安装Containerd
从地址https://containerd.io/downloads/
中选择Binaries (.tar.gz)
进行下载(containerd-<VERSION>-<OS>-<ARCH>.tar.gz)。
解压缩文件到目录/usr/local/
:
tar zxvf containerd-1.6.28-linux-amd64.tar.gz -C /usr/local/
下载系统脚本,使其可以随系统启动
下载地址为https://raw.githubusercontent.com/containerd/containerd/main/containerd.service,大概的内容如下:
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
创建文件/etc/systemd/system/containerd.service
,将上述内容复制到此文件中并保存。
运行命令
systemctl daemon-reload
systemctl enable --now containerd
安装runc
Containerd虽然是一个容器运行时,但它本身并不直接负责运行容器。容器的实际运行是由runc这个工具来控制的。runc是一个轻量级的容器运行工具,它是根据OCI(Open Container Initiative)规范实现的容器运行时。runc就是OCI规范的一个具体实现,它可以接收containerd发送的指令,然后创建、启动、停止和删除容器。
从地址https://github.com/opencontainers/runc/releases中下载二进制包runc.<ARCH>
,将其安装到/usr/local/sbin/runc
目录下:
install -m 755 runc.amd64 /usr/local/sbin/runc
安装CNI插件
Containerd是一个容器运行时,它负责管理容器的生命周期,包括创建、运行、停止和删除容器。然而,Containerd本身并不提供容器网络的功能,为了实现容器网络,就需要依赖于CNI(Container Network Interface)插件。
从地址https://github.com/containernetworking/plugins/releases中下载压缩包cni-plugins-<OS>-<ARCH>-<VERSION>.tgz
,将其解压到/opt/cni/bin
目录下:
mkdir -p /opt/cni/bin
tar xzvf cni-plugins-linux-amd64-v1.4.0.tgz -C /opt/cni/bin
自定义配置
配置文件:/etc/containerd/config.toml
默认的配置可以先通过命令生成,然后再去做修改:
containerd config default > /etc/containerd/config.toml
配置国内镜像源
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint=["https://******.mirror.aliyuncs.com"]
官方使用指南地址
https://github.com/containerd/containerd/blob/main/docs/getting-started.md