k8s 切换容器引擎containerd
k8s-切换容器引擎containerd
1.k8s-切换容器引擎containerd
-
1、配置先前条件
[root@k8s-node02 ~]# cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf > overlay > br_netfilter > EOF overlay br_netfilter [root@k8s-node02 ~]# modprobe overlay [root@k8s-node02 ~]# modprobe br_netfilter [root@k8s-node02 ~]# vim /etc/sysctl.d/99-sysctl-cri.conf [root@k8s-node02 ~]# cat /etc/sysctl.d/99-sysctl-cri.conf net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 [root@k8s-node02 ~]# sysctl --system
-
2、 安装containerd
[root@k8s-node02 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 [root@k8s-node02 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo [root@k8s-node02 ~]# yum install -y containerd.io [root@k8s-node02 ~]# mkdir -p /etc/containerd [root@k8s-node02 ~]# containerd config default > /etc/containerd/config.toml [root@k8s-node02 ~]# systemctl restart containerd.service
-
3、停止docker服务
[root@k8s-node02 ~]# /bin/systemctl stop docker Warning: Stopping docker.service, but it can still be activated by: docker.socket [root@k8s-node02 ~]# /bin/systemctl stop docker.socket
-
4、启动containerd服务
[root@k8s-node02 ~]# /bin/systemctl start containerd.service
-
5、修改配置文件
- pause 镜像设置过阿里云镜像仓库地址
- cgroups 驱动设置为systemd
- 拉取docker hub镜像配置加速地址设置为阿里云镜像仓库地址
[root@k8s-node02 ~]# vim /etc/containerd/config.toml [plugins."io.containerd.grpc.v1.cri"] sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.2" ..... [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] SystemdCgroup = true .... [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"] endpoint = ["https://b9pmyelo.mirror.aliyuncs.com"] ....
-
6、重启
[root@k8s-node02 ~]# /bin/systemctl restart containerd.service
-
7、 配置kubelet使用containerd
[root@k8s-node02 ~]# vim /etc/sysconfig/kubelet [root@k8s-node02 ~]# cat /etc/sysconfig/kubelet KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --cgroup-driver=systemd [root@k8s-node02 ~]# /bin/systemctl restart kubelet
-
8、 主master端验证,容器是否切换为containerd了
[root@k8s-master ~]# kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s-master Ready master 31h v1.19.0 172.17.0.2 <none> CentOS Linux 7 (Core) 3.10.0-1160.11.1.el7.x86_64 docker://20.10.8 k8s-node01 Ready <none> 31h v1.19.0 172.17.0.13 <none> CentOS Linux 7 (Core) 3.10.0-1160.11.1.el7.x86_64 docker://20.10.8 k8s-node02 Ready <none> 31h v1.19.0 172.17.0.16 <none> CentOS Linux 7 (Core) 3.10.0-1160.11.1.el7.x86_64 containerd://1.4.9
2. 恢复到docker引擎
-
编写kubelet文件
[root@k8s-node02 ~]# vim /etc/sysconfig/kubelet [root@k8s-node02 ~]# cat /etc/sysconfig/kubelet KUBELET_EXTRA_ARGS=--container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --cgroup-driver=systemd # 修改为原来模式 [root@k8s-node02 ~]# vim /etc/sysconfig/kubelet [root@k8s-node02 ~]# cat /etc/sysconfig/kubelet KUBELET_EXTRA_ARGS=
-
停止containerd
[root@k8s-node02 ~]# /bin/systemctl stop containerd
-
重新启动docker
[root@k8s-node02 ~]# /bin/systemctl restart docker [root@k8s-node02 ~]# ps -ef |grep docker root 4901 1 1 20:38 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock root 5199 31986 0 20:38 pts/1 00:00:00 grep --color=auto docker
-
重启kubelet
[root@k8s-node02 ~]# /bin/systemctl restart kubelet.service
-
验证是否恢复到docker引擎
[root@k8s-master ~]# kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s-master Ready master 2d6h v1.19.0 172.17.0.2 <none> CentOS Linux 7 (Core) 3.10.0-1160.11.1.el7.x86_64 docker://20.10.8 k8s-node01 Ready <none> 2d6h v1.19.0 172.17.0.13 <none> CentOS Linux 7 (Core) 3.10.0-1160.11.1.el7.x86_64 docker://20.10.8 k8s-node02 Ready <none> 2d6h v1.19.0 172.17.0.16 <none> CentOS Linux 7 (Core) 3.10.0-1160.11.1.el7.x86_64 docker://20.10.8