k8s集群升级

目录

[1. 部署cri-docker (所有集群节点)](#1. 部署cri-docker (所有集群节点))

[2. 升级master节点](#2. 升级master节点)

[3. 升级worker节点](#3. 升级worker节点)

[4. 部署containerd](#4. 部署containerd)


1. 部署cri-docker (所有集群节点)

k8s从1.24版本开始移除了dockershim,所以需要安装cri-docker插件才能使用docker

软件下载:GitHub - Mirantis/cri-dockerd: dockerd as a compliant Container Runtime Interface for Kubernetes
安装

rpm -ivh  cri-dockerd-0.3.5.20231016182601.cd730ff8-0.el7.x86_64.rpm


配置cri-docker

vim /usr/lib/systemd/system/cri-docker.service

[Service]
Type=notify
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=cni --pod-infra-container-image=reg.westos.org/k8s/pause:3.7

systemctl daemon-reload
systemctl  enable --now cri-docker
ll /var/run/cri-dockerd.sock

2. 升级master节点

首先上传镜像到harbor仓库,便于升级

docker load -i k8s-v1.24.17.tar
docker images | grep k8s
docker push reg.westos.org/k8s/kube-apiserver:v1.24.17
docker push  reg.westos.org/k8s/kube-proxy:v1.24.17
docker push reg.westos.org/k8s/kube-scheduler:v1.24.17
docker push reg.westos.org/k8s/kube-controller-manager:v1.24.17
docker push reg.westos.org/k8s/pause:3.7


升级kubeadm 执行升级

yum install -y kubeadm-1.24.17-0
kubeadm upgrade plan


修改节点套接字

kubectl edit nodes k8s1

kubeadm.alpha.kubernetes.io/cri-socket: unix:///var/run/cri-dockerd.sock

kubeadm upgrade apply v1.24.17



腾空节点

kubectl drain k8s1 --ignore-daemonsets


升级kubelet

yum install -y kubelet-1.24.17-0 kubectl-1.24.17-0


配置kubelet使用cri-docker

vim /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS="--pod-infra-container-image=reg.westos.org/k8s/pause:3.7 --container-runtime=remote --container-runtime-endpoint=unix:///var/run/cri-dockerd.sock"


重启kubelet

systemctl daemon-reload 
systemctl  restart kubelet 


解除节点保护

kubectl uncordon k8s1

完成升级

3. 升级worker节点

升级kubeadm 执行升级

yum install -y kubeadm-1.24.17-0
kubeadm upgrade node

腾空节点 #需要在master节点执行

kubectl drain k8s2 --ignore-daemonsets
kubectl drain k8s3 --ignore-daemonsets


升级kubelet

yum install -y kubelet-1.24.17-0 kubectl-1.24.17-0


配置kubelet使用cri-docker

vim /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS="--pod-infra-container-image=reg.westos.org/k8s/pause:3.7 --container-runtime=remote --container-runtime-endpoint=unix:///var/run/cri-dockerd.sock"


修改节点套接字 #需要在master节点执行

kubectl edit nodes k8s2
...
kubeadm.alpha.kubernetes.io/cri-socket: unix:///var/run/cri-dockerd.sock


重启kubelet

diff 复制代码
systemctl daemon-reload 
systemctl  restart kubelet 


解除节点保护 #需要在master节点执行

diff 复制代码
kubectl uncordon k8s2


其它节点依此类推

完成升级

4. 部署containerd

k8s从1.24版本开始移除了dockershim,所以我们不在使用docker,选用containerd。
k8s1、k8s2、k8s3在配置前需要重置节点

kubeadm reset
kubeadm reset  --cri-socket unix:///var/run/cri-dockerd.sock
kubeadm reset  --cri-socket unix:///var/run/cri-dockerd.sock

k8s1:

k8s2,3


所有节点清除iptables规则

iptables -F
iptables -F -t nat


禁用所有节点docker和cri-docker服务

diff 复制代码
systemctl  disable --now docker
systemctl  disable --now docker.socket
systemctl  disable --now cri-docker


之前部署过docker,containerd默认已经安装

修改配置

diff 复制代码
containerd config default | tee /etc/containerd/config.toml
cd /etc/containerd/
vim config.toml
...
sandbox_image = "reg.westos.org/k8s/pause:3.7"
...
SystemdCgroup = true


修改配置文件

diff 复制代码
vim /etc/containerd/config.toml
...
[plugins."io.containerd.grpc.v1.cri".registry]
      config_path = "/etc/containerd/certs.d"
mkdir -p /etc/containerd/certs.d/docker.io

vim /etc/containerd/certs.d/docker.io/hosts.toml

server = "https://registry-1.docker.io"

[host."https://reg.westos.org"]
  capabilities = ["pull", "resolve", "push"]
  skip_verify = true

拷贝证书

diff 复制代码
mkdir -p /etc/containerd/certs.d/reg.westos.org
cp /etc/docker/certs.d/reg.westos.org/ca.crt /etc/containerd/certs.d/reg.westos.org/
systemctl  restart containerd
scp -r certs.d/ config.toml k8s2:/etc/containerd/
scp -r certs.d/ config.toml k8s3:/etc/containerd/


k8s2,3
systemctl disable --now docker cri-docker docker.socket
systemctl  enable --now containerd
crictl config runtime-endpoint unix:///run/containerd/containerd.sock


启动containerd

systemctl  enable --now containerd
systemctl  restart containerd
crictl config runtime-endpoint unix:///run/containerd/containerd.sock
crictl img
crictl pull reg.westos.org/k8s/pause:3.6

集群初始化

diff 复制代码
kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository reg.westos.org/k8s --kubernetes-version v1.24.17
kubectl apply -f kube-flannel.yml

相关推荐
码农派大星。2 分钟前
Spring Boot 配置文件
java·spring boot·后端
顾北川_野9 分钟前
Android 手机设备的OEM-unlock解锁 和 adb push文件
android·java
江深竹静,一苇以航12 分钟前
springboot3项目整合Mybatis-plus启动项目报错:Invalid bean definition with name ‘xxxMapper‘
java·spring boot
confiself28 分钟前
大模型系列——LLAMA-O1 复刻代码解读
java·开发语言
Wlq041532 分钟前
J2EE平台
java·java-ee
XiaoLeisj39 分钟前
【JavaEE初阶 — 多线程】Thread类的方法&线程生命周期
java·开发语言·java-ee
豪宇刘1 小时前
SpringBoot+Shiro权限管理
java·spring boot·spring
Elaine2023911 小时前
02多线程基础知识
java·多线程
gorgor在码农1 小时前
Redis 热key总结
java·redis·热key
百事老饼干1 小时前
Java[面试题]-真实面试
java·开发语言·面试