目录

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

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

2.安装containerd

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

修改kubeadm-flags.env 变量:

1
KUBELET_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

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

查看状态:

kubectl get nodes
systemctl status kubelet

Worker 节点操作

1.升级kubeadm

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

2.安装containerd

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

修改kubeadm-flags.env 变量:

1
KUBELET_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

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

查看状态:

systemctl status kubelet

4.优化的维护节点

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