之前有记录使用containerd部署k8s集群的笔记,这次记录一个已有k8s集群从docker切换到containerd方法的笔记,下面就介绍切换的操作过程
首先下载containerd包
wget https://github.com/containerd/containerd/releases/download/v1.7.10/cri-containerd-1.7.10-linux-amd64.tar.gz
部署containerd
tar -zxvf cri-containerd-1.7.10-linux-amd64.tar.gz -C /
然后创建containerd配置文件目录
mkdir -p /etc/containerd containerd config default >/etc/containerd/config.toml
config.toml中配置容器运行的cgroup driver改为systemd
SystemdCgroup = false #改为 SystemdCgroup = true
sandbox_image 配置改为 "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"
卸载docker
rpm -qa |grep -i docker rpm -e * #列出来的包都可以删除通过这个命令删除
同时我们还是需要替换下runc文件,默认containerd带的有点问题
wget https://github.com/opencontainers/runc/releases/download/v1.1.10/runc.amd64 rm -rf /usr/local/sbin/runc mv runc.amd64 /usr/local/sbin/runc chmod +x /usr/local/sbin/runc
然后设置containerd开机启动
systemctl enable containerd --now systemctl start containerd
设置crictl
cat >/etc/crictl.yaml<<EOF runtime-endpoint: unix:///var/run/containerd/containerd.sock image-endpoint: unix:///var/run/containerd/containerd.sock timeout: 10 debug: false EOF
然后重启containerd
systemctl restart containerd
接着我们切换K8s的运行时,修改kubeadm-flags.env配置如下:
KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime-endpoint=/run/containerd/containerd.sock --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"
有些部署方式可能运行时参数写在/etc/sysconfig/kubelet文件中,可以根据自己当时部署k8s配置来修改运行时的配置。
然后重启kubelet
systemctl restart kubelet
使用kubectl get node命令查出来CONTAINER-RUNTIME列显示为containerd://1.7.10说明切换成功。