kubernetes 从1.23.x 升级到 1.24.x

kubernetes 从1.23.x 升级到 1.24.x

k8s 在1.24.x之后的版本放弃了和 docker 的兼容,使用 containerd 作为底层的容器,直接参照官方文档的资料进行更新就会报错。因为你没有安装 containerd,所以要安装 containerd 并配置才能正确的升级 k8s
我用的是CentOS7.9的版本,因此以下操作都是在CentOS下操作。

Master 节点操作

1.升级 kubeadm

1yum install -y kubeadm-1.24.2-0 --disableexcludes=kubernetes
2kubeadm version
3kubeadm upgrade plan
4sudo kubeadm upgrade apply v1.24.2

2.安装 containerd

1yum install containerd.io -y
2containerd config default > /etc/containerd/config.toml
3vim /var/lib/kubelet/kubeadm-flags.env

修改 kubeadm-flags.env 变量:

1KUBELET_KUBEADM_ARGS="--pod-infra-container-image=k8s.gcr.io/pause:3.6 --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock"

3.升级 kubelet

1yum install -y kubelet-1.24.2-0 kubectl-1.24.2-0 --disableexcludes=kubernetes
2systemctl daemon-reload && systemctl restart containerd  && systemctl restart kubelet

查看状态:

kubectl get nodes
systemctl status kubelet

Worker 节点操作

1.升级 kubeadm

1yum install -y kubeadm-1.24.2-0 --disableexcludes=kubernetes
2kubeadm version
3kubeadm upgrade plan
4sudo kubeadm upgrade node

2.安装 containerd

1yum install containerd.io -y
2containerd config default > /etc/containerd/config.toml
3vim /var/lib/kubelet/kubeadm-flags.env

修改 kubeadm-flags.env 变量:

1KUBELET_KUBEADM_ARGS="--pod-infra-container-image=k8s.gcr.io/pause:3.6 --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock"

3.升级 kubelet

1yum install -y kubelet-1.24.2-0 kubectl-1.24.2-0 --disableexcludes=kubernetes
2systemctl daemon-reload && systemctl restart containerd  && systemctl restart kubelet

查看状态:

systemctl status kubelet

4.优化的维护节点

1# 设置为不可调度
2kubectl cordon <nodename>
3# 优雅排出容器
4kubectl drain <nodename> --ignore-daemonsets --delete-emptydir-data
5# 确认维护完成之后,恢复正常
6kubectl uncordon <nodename>