其他分享
首页 > 其他分享> > k8s 1.20.6 将docker切换为containerd

k8s 1.20.6 将docker切换为containerd

作者:互联网

一、环境介绍

官方文档:https://kubernetes.io/zh/docs/setup/production-environment/container-runtimes/#containerd

[root@master ~]# kubectl get node  -o wide
NAME     STATUS   ROLES                  AGE     VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master   Ready    control-plane,master   4m24s   v1.20.6   192.168.11.67   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7
node1    Ready    <none>                 4m      v1.20.6   192.168.11.68   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7
node2    Ready    <none>                 3m57s   v1.20.6   192.168.11.69   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7

  

二、在master上操作

1、将需要切换的node改为不可调度

kubectl cordon node1

2、驱逐该node上的pod资源

kubectl drain node1 --delete-local-data --force --ignore-daemonsets

3、查看  

[root@master ~]# kubectl get node
NAME     STATUS                     ROLES                  AGE   VERSION
master   Ready                      control-plane,master   15m   v1.20.6
node1    Ready,SchedulingDisabled   <none>                 14m   v1.20.6
node2    Ready                      <none>                 14m   v1.20.6

  

三、在切换引擎的node服务器上操作

1、配置先决条件

cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# 设置必需的 sysctl 参数,这些参数在重新启动后仍然存在。
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

# 应用 sysctl 参数而无需重新启动
sudo sysctl --system

  

2、安装containerd(因为我们是用的docker引擎。所以containerd已经安装好了。所以就不用安装containerd了)

 

3、配置containerd的config.toml文件(覆盖旧的配置config.toml文件)

containerd config default | sudo tee /etc/containerd/config.toml

  

4、修改config.toml配置

sandbox_image:将镜像地址替换为国内阿里云的
SystemdCgroup:指定使用systemd作为Cgroup的驱动程序(在options下一行添加的内容)
endpoint:修改镜像加速地址

[root@node1 ~]# cat -n  /etc/containerd/config.toml |egrep "sandbox_image|SystemdCgroup |endpoint "
    57	    sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2"    
    97	          SystemdCgroup = true
   106	          endpoint = ["https://1nj0zren.mirror.aliyuncs.com"]

  

5、重启containerd

systemctl restart containerd.service
systemctl enable containerd.service

  

6、配置kubelet使用containerd

[root@node1 ~]# cat  /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --cgroup-driver=systemd"

  

7、重启kubelet

systemctl restart kubelet

  

四、查看容器引擎是否成功切换为containerd

1、查看容器引擎是否成功切换为containerd

[root@master ~]# kubectl get node -o wide
NAME     STATUS                     ROLES                  AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master   Ready                      control-plane,master   22m   v1.20.6   192.168.11.67   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7
node1    Ready,SchedulingDisabled   <none>                 22m   v1.20.6   192.168.11.68   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   containerd://1.4.6
node2    Ready                      <none>                 21m   v1.20.6   192.168.11.69   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7

  

2、取消node节点不可被调度的标记

[root@master ~]# kubectl uncordon  node1
node/node1 uncordoned
[root@master ~]# kubectl get node -o wide
NAME     STATUS   ROLES                  AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master   Ready    control-plane,master   23m   v1.20.6   192.168.11.67   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7
node1    Ready    <none>                 23m   v1.20.6   192.168.11.68   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   containerd://1.4.6
node2    Ready    <none>                 23m   v1.20.6   192.168.11.69   <none>        CentOS Linux 7 (Core)   3.10.0-1160.25.1.el7.x86_64   docker://20.10.7

  

 

标签:containerd,192.168,v1.20,node1,master,Ready,docker,k8s
来源: https://www.cnblogs.com/zhangb8042/p/14958755.html