k8s 1.23升级1.24

发布于:2025-04-06 ⋅ 阅读:(20) ⋅ 点赞:(0)

0、简介

这里只用3台服务器来做一个简单的集群,当前版本是1.23.17目标升级到1.24.17

地址 主机名
192.168.160.40 kuber-master-1
192.168.160.41 kuber-master-2
192.168.160.42 kuber-node-1

我这里设置的master2可调度pod,将master2的污点去掉

kubectl describe nodes node | grep Taint

kubectl taint nodes kuber-master-2 node-role.kubernetes.io/master:NoSchedule-

版本对应关系

containerd对应

ingress对应

https://github.com/kubernetes/ingress-nginx

当前ingress1.4.0,先升级集群到1.25

升级ingress到1.9.6,升级集群到1.30

升级ingress到1.12.1 

calico对应

System requirements | Calico Documentation

升级calico到3.24

1、升级calico

这里旧版本的calico是3.20,先升级到3.24版本。

curl https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/calico.yaml -o calico.yaml

下载3.24版本,直接进行apply操作,会对旧版本覆盖。

kubectl apply -f calico.yam

2、升级k8s版本--master执行

(1)升级kubeadm

yum install -y kubeadm-1.24.17-0 --disableexcludes=kubernetes

kubeadm version 查看当前kubeadm的版本

(2)查看执行计划

kubeadm upgrade plan

(3)修改runtime

kubectl edit nodes kuber-master-1

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

修改为

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

(4)配置containerd修改默认Cgroup驱动

containerd config default > /etc/containerd/config.toml

sed -i 's#SystemdCgroup = false#SystemdCgroup = true#g' /etc/containerd/config.toml

vim /var/lib/kubelet/kubeadm-flags.env

KUBELET_KUBEADM_ARGS="--network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.6"

修改为

KUBELET_KUBEADM_ARGS="--pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.6 --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock"

systemctl daemon-reload

systemctl restart containerd #重启containerd

systemctl restart kubelet #重启kubelet

(5)定义 crictl 如何连接到容器运行时

cat >/etc/crictl.yaml<<EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
EOF

# 加载
systemctl daemon-reload
systemctl restart containerd

(6)开始升级

kubeadm upgrade apply v1.24.17

(7)升级kubelet和kubectl

kubectl drain k8s-master01 --ignore-daemonsets

yum -y install kubelet-1.24.17 kubectl-1.24.17

systemctl daemon-reload

systemctl restart kubelet

kubectl uncordon k8s-master01

(8)升级其他控制节点

不需要执行kubeadm upgrade plan
kubeadm upgrade node

替换 kubeadm upgrade apply
其他流程一样。

3、升级k8s版本--node执行

yum -y install kubeadm-1.24.17

驱逐node上的pod

kubectl drain  k8s-node-01  --ignore-daemonsets

同master一样修改运行时和配置

做完1-5步就行

kubeadm upgrade node

升级kubelet和kubectl

kubectl drain k8s-node-01 --ignore-daemonsets

yum -y install kubelet-1.24.17 kubectl-1.24.17

systemctl daemon-reload

systemctl restart kubelet

kubectl uncordon k8s-node-01