基于docker和cri-dockerd部署kubernetes v1.25.3

基于docker和cri-dockerd部署kubernetes v1.25.31、环境准备1-1、主机清单主机名IP地址系统版本k8s-master01 k8s-master01.wang.org kubeapi.wang.org kubeapi10.0.0.101Ubuntu2004k8s-master02 k8s-master02.wang.org10.0.0.102Ubuntu2004k8s-master03 k8s-master03.wang.org10.0.0.103Ubuntu2004k8s-node01 k8s-node01.wang.org10.0.0.111Ubuntu2004k8s-node02 k8s-node02.wang.org10.0.0.112Ubuntu2004k8s-node03 k8s-node03.wang.org10.0.0.113Ubuntu20041-2、软件清单 docker-ce    20.10.21 cri-dockerd  0.2.6 kubeadm      1.25.3 flannel      0.20.11-3、系统基础环境1-3-1、关闭防火墙 #所有节点执行: [root@k8s-master01 ~]# ufw disable [root@k8s-master01 ~]# ufw status1-3-2、时间同步 #所有节点执行: [root@k8s-master01 ~]# apt install -y chrony [root@k8s-master01 ~]# systemctl restart chrony [root@k8s-master01 ~]# systemctl status chrony [root@k8s-master01 ~]# chronyc sources1-3-3、主机名互相解析 #所有节点执行: [root@k8s-master01 ~]# vim /etc/hosts 10.0.0.101 k8s-master01 k8s-master01.wang.org kubeapi.wang.org kubeapi 10.0.0.102 k8s-master02 k8s-master02.wang.org 10.0.0.103 k8s-master03 k8s-master03.wang.org 10.0.0.111 k8s-node01 k8s-node01.wang.org 10.0.0.112 k8s-node02 k8s-node02.wang.org 10.0.0.113 k8s-node03 k8s-node03.wang.org ? [root@k8s-master01 ~]# cat /etc/hosts        1-3-4、禁用swap #所有节点执行: [root@k8s-master01 ~]# sed -r -i '/\/swap/s@^@#@' /etc/fstab [root@k8s-master01 ~]# swapoff -a [root@k8s-master01 ~]# systemctl --type swap ? #若不禁用Swap设备,需要在后续编辑kubelet的配置文件/etc/default/kubelet,设置其忽略Swap启用的状态错误,内容:KUBELET_EXTRA_ARGS="--fail-swap-on=false"2、安装docker #所有节点执行: ? #安装必要的一些系统工具 [root@k8s-master01 ~]# apt update [root@k8s-master01 ~]# apt -y install apt-transport-https ca-certificates curl software-properties-common ? #安装GPG证书 [root@k8s-master01 ~]# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add - OK #写入软件源信息 [root@k8s-master01 ~]# add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" ? #更新并安装Docker-CE [root@k8s-master01 ~]# apt update [root@k8s-master01 ~]# apt install -y docker-ce #所有节点执行: kubelet需要让docker容器引擎使用systemd作为CGroup的驱动,其默认值为cgroupfs , 因而,我们还需要编辑docker的配置文件/etc/docker/daemon.json,添加如下内容,其中的registry-mirrors用于指明使用的镜像加速服务 。 ? [root@k8s-master01 ~]# vim /etc/docker/daemon.json {     "registry-mirrors": [         "https://docker.mirrors.ustc.edu.cn",         "https://hub-mirror.c.163.com",         "https://reg-mirror.qiniu.com",         "https://registry.docker-cn.com" ],     "exec-opts": ["native.cgroupdriver=systemd"],     "log-driver": "json-file",     "log-opts": {     "max-size": "200m" },     "storage-driver": "overlay2" } ? [root@k8s-master01 ~]# systemctl daemon-reload [root@k8s-master01 ~]# systemctl start docker [root@k8s-master01 ~]# systemctl enable docker [root@k8s-master01 ~]# docker version Client: Docker Engine - Community  Version:           20.10.21 #注:kubeadm部署Kubernetes集群的过程中,默认使用Google的Registry服务k8s.gcr.io上的镜像,由于2022年仓库已经改为registry.k8s.io,国内可以直接访问,所以现在不需要镜像加速或者绿色上网就可以拉镜像了,如果使用国内镜像请参考https://blog.51cto.com/dayu/58113073、安装cri-dockerd #所有节点执行: #下载地址:https://github.com/Mirantis/cri-dockerd [root@k8s-master01 ~]# apt install ./cri-dockerd_0.2.6.3-0.ubuntu-focal_amd64.deb -y ? #完成安装后,相应的服务cri-dockerd.service便会自动启动 [root@k8s-master01 ~]#systemctl status cri-docker.service4、安装kubeadm、kubelet和kubectl #所有节点执行: #在各主机上生成kubelet和kubeadm等相关程序包的仓库,可参考阿里云官网 [root@k8s-master01 ~]# apt update [root@k8s-master01 ~]# apt install -y apt-transport-https curl [root@k8s-master01 ~]# curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - [root@k8s-master01 ~]#cat <<EOF >/etc/apt/sources.list.d/kubernetes.list > deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main > EOF ? ? #更新仓库并安装 [root@k8s-master01 ~]# apt update [root@k8s-master01 ~]# apt install -y kubelet kubeadm kubectl ? #注意:先不要启动,只是设置开机自启动 [root@k8s-master01 ~]# systemctl enable kubelet ? #确定kubeadm等程序文件的版本 [root@k8s-master01 ~]# kubeadm version kubeadm version: &version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-12T10:55:36Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"linux/amd64"} ?

推荐阅读