目录
写在前面:
一、关闭docker,清除策略
二、Containerd部署
注意:如果曾经装过 docker ,那么 containerd 就存在与主机里修改 Containerd 配置文件,启动 Containerd
替代docker的指令
初始化集群
写在前面:
k8s 1.24将弃用 Dockershim ,替代适配器名为 cri-dockerd
上一篇博客中我们使用docker部署了一个集群,其中server1是master
一、关闭docker,清除策略
[root@server1 ~]# kubeadm reset ##确认删除,三台设备上都要做
[root@server1 ~]# iptables -L ##创建k8s时会有很多策略,会影响后面的初始化,所以直接重启主机清楚策略
[root@server1 ~]# reboot ##三台主机都做,当然也可以用命令行清除iptables策略
[root@server1 ~]# systemctl disable --now docker
[root@server1 ~]# systemctl disable --now docker.socket
[root@server1 ~]# ssh server2 systemctl disable --now docker
[root@server1 ~]# ssh server2 systemctl disable --now docker.socket
[root@server1 ~]# ssh server3 systemctl disable --now docker
[root@server1 ~]# ssh server3 systemctl disable --now docker.socket
[root@server1 ~]# docker ps ##此时可以看见docker已经没有运行了
二、Containerd部署
注意:如果曾经装过 docker ,那么 containerd 就存在与主机里
修改 Containerd 配置文件,启动 Containerd
[root@server1 ~]# cd /etc/containerd/
[root@server1 ~]# ls
config.toml ## containerd 的默认配置文件
[root@server1 containerd]# containerd config default ##列出defaul配置
[root@server1 containerd]# containerd config default > config.toml
[root@server1 containerd]# vim config.toml
将 56 sandbox_image = "k8s.gcr.io/pause:3.5" ##需要科学上网,我的网路条件下不了
62 systemd_cgroup = false ##
改为 56 sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.5"
##阿里云镜像仓库,如果有私有仓库更好
62 systemd_cgroup = true
[root@server1 containerd]# systemctl enable --now containerd.service
[root@server1 containerd]# ll /run/containerd/containerd.sock
[root@server1 containerd]# scp config.toml server2:/etc/containerd/
[root@server1 containerd]# scp config.toml server3:/etc/containerd/
[root@server1 containerd]# ssh server2 systemctl enable --now containerd.service
[root@server1 containerd]# ssh server3 systemctl enable --now containerd.service
[root@server1 containerd]# modprobe overlay ##加载overlay模块
[root@server1 containerd]# cd /etc/modules-load.d/
[root@server1 modules-load.d]# vim containerd.conf
br_netfilter
[root@server1 modules-load.d]# sysctl -a | grep ip_forward ##有 net.ipv4.ip_forward = 1,如果是ubuntu需要进入文件确认一下
[root@server1 modules-load.d]# vim /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1 ##默认有,可以不写进去
[root@server1 modules-load.d]# sysctl --system
[root@server1 modules-load.d]# scp containerd.conf server2:/etc/modules-load.d/
[root@server1 modules-load.d]# scp containerd.conf server3:/etc/modules-load.d/
[root@server1 modules-load.d]# scp /etc/sysctl.d/k8s.conf server2:/etc/sysctl.d/
[root@server1 modules-load.d]# scp /etc/sysctl.d/k8s.conf server3:/etc/sysctl.d/
[root@server1 modules-load.d]# ssh server2 sysctl --system
[root@server1 modules-load.d]# ssh server3 sysctl --system
替代docker的指令
下载crictl,解压后放到 /usr/local/bin/ 下可以了
crictl config runtime-endpoint unix:///run/contaiberd/contaiberd.sock
会在 /etc/ 生成 crictl.yml 文件
systemctl restart containerd.service ##所有节点都要执行
初始化集群
#使用docker中初始化的命令,看看会发生什么
[root@server1 ~]# kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers
#查看报错,kubeadm去找docker了,除非卸载docker,否则都会去找docker
[root@server1 ~]# kubeadm config print init-defaults > kubeadm-init.yaml
root@server1 ~]# vim kubeadm-init.yaml
#修改一下内容
12 advertiseAddress: 172.25.31.1 ##master ip地址
15 criSocket: /run/containerd/containerd.sock ##把cri写死containerd
17 name: server1
30 imageRepository: registry.aliyuncs.com/google_containers ##修改拉取仓库
32 kubernetesVersion: 1.22.1 ##版本,可以不改,1.22.1是cka考试所用环境
35 podSubnet: 10.244.0.0/16 ##手动添加pod的子网段,使用flannel网络组件时必须添加
[root@server1 ~]# yum downgrade kubeadm-1.22.1-0 kubelet-1.22.1-0 kubectl-1.22.1-0 -y
[root@server1 ~]# ssh server2 yum downgrade kubeadm-1.22.1-0 kubelet-1.22.1-0 kubectl-1.22.1-0 -y
[root@server1 ~]# ssh server3 yum downgrade kubeadm-1.22.1-0 kubelet-1.22.1-0 kubectl-1.22.1-0 -y
[root@server1 ~]# systemctl daemon-reload
[root@server1 ~]# systemctl restart kubelet.service ##server2 server3 同理
[root@server1 ~]# kubeadm config images list --config kubeadm-init.yaml ##指定配置文件,列出镜像
[root@server1 ~]# kubeadm config images pull --config kubeadm-init.yaml
[root@server1 ~]# kubeadm init --config kubeadm-init.yaml ##初始化镜像
[root@server1 ~]# kubectl apply -y kube-flannel.yml
[root@server2 ~]# kubeadm join 172.25.31.1:6443 --token ifn3y4.i2bxx5h2eiktkzne --discovery-token-ca-cert-hash sha256:7df54bba99623afb2ad054ec64c530d2ffbf4fb09d38240fcb26b7a6754c3eac
[root@server3 ~]# kubeadm join 172.25.31.1:6443 --token ifn3y4.i2bxx5h2eiktkzne --discovery-token-ca-cert-hash sha256:7df54bba99623afb2ad054ec64c530d2ffbf4fb09d38240fcb26b7a6754c3eac