1、 Containerd
安装docker-ce-20.10(所有节点均需要安装):
[root@localhost /]# yum install docker-ce-20.10.* docker-ce-cli-20.10.* -y
节点需要安装,但无需启动Docker,只需要配置和启动Containerd即可
全部节点配置Containerd所需的模块(安装和配置的先决条件)
[root@localhost /]# cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
全部节点加载模块
modprobe -- overlay &&
modprobe -- br_netfilter
配置Containerd所需内核
[root@localhost /]# cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
加载内核
[root@localhost /]# sysctl --system
配置Containerd的配置文件
[root@localhost /]# mkdir -p /etc/containerd
[root@localhost /]# containerd config default | tee /etc/containerd/config.toml
修改配置文件(使用 systemd cgroup 驱动程序)
[root@localhost /]# vim /etc/containerd/config.toml
---------------------------------------
# 找到containerd.runtimes.runc.options,将SystemdCgroup = false改成SystemdCgroup = true
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
# 同时将sandbox_image的Pause镜像改成符合自己版本的地址:
# registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
启动Containerd,并配置开机自启动
[root@localhost /]# systemctl daemon-reload &
[root@localhost /]# systemctl enable --now containerd
配置crictl客户端连接的运行时位置
[root@localhost /]# cat > /etc/crictl.yaml <<EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
EOF
- Docker
如果选择Docker作为Runtime,安装步骤较Containerd较为简单,只需要安装并启动即可
安装docker-ce 20.10
[root@localhost /]# yum install docker-ce-20.10.* docker-ce-cli-20.10.* -y
配置docker
[root@localhost /]# mkdir -p /etc/docker
# 由于新版Kubelet建议使用systemd,所以把Docker的CgroupDriver也改成systemd,
# 同时配置镜像仓库加速器(阿里云),提升获取Docker官方镜像的速度
# overlay2:默认的,需文件系统为xfs,且支持d_type
# 注意格式,勿漏掉逗号
---------------------------------------------------------
[root@localhost /]# cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"registry-mirrors": ["https://ohdpuoqu.mirror.aliyuncs.com"],
"live-restore": true
}
EOF
设置开机自启动Docker
[root@localhost /]# systemctl daemon-reload && systemctl enable --now docker
docker生产环境重要配置
Docker Root Dir # 生产环境最好独立挂载SSD硬盘
Live Restore Enabled # 重启docker,但不重启容器,上文中已配置