安装Containerd
1. Ubuntu安装containerd
以下以Ubuntu为例
说明:安装containerd与安装docker流程基本一致,差别在于不需要安装docker-ce
containerd
: apt-get install -y containerd.iodocker
: apt-get install docker-ce docker-ce-cli containerd.io
1. 卸载旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc
如果需要删除镜像及容器数据则执行以下命令
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
2. 准备包环境
1、更新apt,允许使用https。
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
2、添加docker官方GPG key。
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
3、设置软件仓库源
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3. 安装containerd
# 安装containerd
sudo apt-get update
sudo apt-get install -y containerd.io
# 如果是安装docker则执行:
sudo apt-get install docker-ce docker-ce-cli containerd.io
# 查看运行状态
systemctl enable containerd
systemctl status containerd
安装指定版本
# 查看版本
apt-cache madison containerd
# sudo apt-get install containerd=<VERSION>
4. 修改配置
在 Linux 上,containerd 的默认 CRI 套接字是 /run/containerd/containerd.sock
。
1、生成默认配置
containerd config default > /etc/containerd/config.toml
2、修改CgroupDriver为systemd
k8s官方推荐使用systemd类型的CgroupDriver。
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
3、重启containerd
systemctl restart containerd
2. 离线二进制安装containerd
把containerd
、runc
、cni-plugins
、nerdctl
二进制下载到本地,再上传到对应服务器,解压文件到对应目录,修改containerd配置文件,启动containerd。
#!/bin/bash
set -e
ContainerdVersion=$1
ContainerdVersion=${ContainerdVersion:-1.6.6}
RuncVersion=$2
RuncVersion=${RuncVersion:-1.1.3}
CniVersion=$3
CniVersion=${CniVersion:-1.1.1}
NerdctlVersion=$4
NerdctlVersion=${NerdctlVersion:-0.21.0}
CrictlVersion=$5
CrictlVersion=${CrictlVersion:-1.24.2}
echo "--------------install containerd--------------"
wget https://github.com/containerd/containerd/releases/download/v${ContainerdVersion}/containerd-${ContainerdVersion}-linux-amd64.tar.gz
tar Cxzvf /usr/local containerd-${ContainerdVersion}-linux-amd64.tar.gz
echo "--------------install containerd service--------------"
wget https://raw.githubusercontent.com/containerd/containerd/681aaf68b7dcbe08a51c3372cbb8f813fb4466e0/containerd.service
mv containerd.service /lib/systemd/system/
mkdir -p /etc/containerd/
containerd config default > /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
echo "--------------install runc--------------"
wget https://github.com/opencontainers/runc/releases/download/v${RuncVersion}/runc.amd64
chmod +x runc.amd64
mv runc.amd64 /usr/local/bin/runc
echo "--------------install cni plugins--------------"
wget https://github.com/containernetworking/plugins/releases/download/v${CniVersion}/cni-plugins-linux-amd64-v${CniVersion}.tgz
rm -fr /opt/cni/bin
mkdir -p /opt/cni/bin
tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v${CniVersion}.tgz
echo "--------------install nerdctl--------------"
wget https://github.com/containerd/nerdctl/releases/download/v${NerdctlVersion}/nerdctl-${NerdctlVersion}-linux-amd64.tar.gz
tar Cxzvf /usr/local/bin nerdctl-${NerdctlVersion}-linux-amd64.tar.gz
echo "--------------install crictl--------------"
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v${CrictlVersion}/crictl-v${CrictlVersion}-linux-amd64.tar.gz
tar Cxzvf /usr/local/bin crictl-v${CrictlVersion}-linux-amd64.tar.gz
cat > /etc/crictl.yaml << \EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 2
debug: false
pull-image-on-create: false
EOF
# 启动containerd服务
systemctl daemon-reload
systemctl enable contaienrd
systemctl restart contaienrd
3. Containerd配置代理
由于节点到k8s官方仓库网络不通,或者设备处于内网,可以通过配置http_proxy代理的方式来拉取镜像。
vi /lib/systemd/system/containerd.service
# 添加代理环境变量
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
Environment="HTTP_PROXY=http://squid:3128/" # 添加环境变量代理
Environment="HTTPS_PROXY=http://squid:3128/" # 添加环境变量代理
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
LimitNOFILE=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
# 重启服务
systemctl daemon-reload
systemctl restart containerd
参考:
-
https://github.com/containerd/containerd/blob/main/docs/getting-started.md
-
https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd
-
containerd/containerd.service at main · containerd/containerd · GitHub
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.