原地升級 k8s 集羣 docker 和 containerd 版本

前言

公司用的 k8s 集羣是 “多環境合一” 的方式,集羣流量入口也摒棄了常見的 traefik 和 ingress-nginx,直接用了一個國內不常見的底層基於 Envoy 的 API Gateway 網關服務。當然還有非常多的其他集羣流量入口組件可供選擇,這裏暫不討論。由於這個組件更新迭代也是非常的快速,並且官方文檔很快不展示舊版本文檔了,那麼隨着版本更新,API 版本自然發生了改變,新版本的 API 就沒有任何的參考意義了,因此需要升級組件版本。升級組件版本前提是 docker 版本至少需要 20.10.11,containerd 版本至少是 1.4.11。於是這裏先原地升級這兩個組件。

k8s 的 node 節點維護

儘可能在維護節點之前保證你的有另外的冗餘節點,能夠支撐你當前維護節點上的所有 pod。或者保證你維護這個節點驅逐了所有 pod 後,其他節點能夠承載你這個節點上所有 pod。非常可憐也非常可惜,我這裏節點內存都跑到了 95% 以上,並且領導不給機器,讓我夜裏升級。pod 目前集羣上有超過 5000 個。此時只能硬着頭皮上了。理念是升級完一臺正常後再接着升下一臺。

升級步驟

1、查看原先的 containerd 和 docker 版本

$ containerd -v
containerd containerd.io 1.2.13 7ad184331fa3e55e52b890ea95e65ba581ae3429

$ docker -v
Docker version 19.03.12, build 48a66213fe

2、驅逐 pod

$ kubectl drain k8s-node02.ayunw.cn --ignore-daemonsets --delete-local-data --force

$ kubectl get node
NAME                    STATUS                        
k8s-master01.ayunw.cn   Ready                         
k8s-node01.ayunw.cn     Ready                         
k8s-node02.ayunw.cn     NotReady,SchedulingDisabled
...

3、停止節點上 docker 和 kubelet

systemctl stop kubelet

systemctl stop docker
systemctl stop docker.socket
systemctl stop containerd

4、卸載老版本 docker 並安裝新版本 docker 和 containerd

yum -y remove docker \
              docker-client \
              docker-client-latest \
              docker-common \
              docker-latest \
              docker-latest-logrotate \
              docker-logrotate \
              docker-engine

dnf -y install yum-utils device-mapper-persistent-data lvm2

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

yum makecache

dnf -y install containerd.io-1.4.12-3.1.el8.x86_64.rpm

dnf -y install docker-ce-20.10.11 docker-ce-cli-20.10.11

systemctl daemon-reload
systemctl start docker
systemctl enable docker
systemctl status docker

systemctl status containerd
systemctl enable containerd.service

5、檢查 docker 和 containerd 版本

$ containerd -v && docker -v
containerd containerd.io 1.4.12 7b11cfaabd73bb80907dd23182b9347b4245eb5d
Docker version 20.10.11, build dea9396

6、啓動 kubelet 並恢復節點

systemctl start kubelet
systemctl status kubelet

kubectl uncordon k8s-node02.ayunw.cn

kubectl get node -o wide

最後就能看到版本已經升級完成。

公衆號:運維開發故事

github:https://github.com/orgs/sunsharing-note/dashboard

愛生活,愛運維

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/Q0jnUy8MVh9Nk8nKA8AvVQ