kubernetes版本升级
我当前的kubernetes环境是基于二进制安装部署的
主机IP | services |
---|---|
192.168.21.120 | apiservice,etcd,kubectl,kube-controller-manager,kube-scheduler,docker |
192.168.21.121 | apiservice,etcd,kubectl,kube-controller-manager,kube-scheduler,docker |
192.168.21.122 | apiservice,etcd,kubectl,kube-controller-manager,kube-scheduler,docker |
192.168.21.100 | kubelet,kube-proxy,docker |
[root@k8s-master1 kubernetes-v1.22.1]# kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:45:37Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:39:34Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
更新k8s版本
操作步骤:
1、到nginx禁用master1配置
2、若master1有pod,先将master1设置维护状态,驱逐所有pod
3、下载新版本k8s,复制原k8s目录改名为新目录
4、复制并覆盖新组件服务至新k8s目录,更新软链接
5、重启相关服务,检查版本是否正常
6、取消维护状态,启用nginx配置
7、其他节点一样重复操作
1.到nginx禁用master1配置
[root@k8s-master1 nginx]# pwd
/etc/nginx
[root@k8s-master1 nginx]# vi nginx.conf
stream {
upstream kube-apiserver {
# server 192.168.21.120:6443 max_fails=3 fail_timeout=30s;
server 192.168.21.121:6443 max_fails=3 fail_timeout=30s;
server 192.168.21.122:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 16443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}
[root@k8s-master1 nginx]# nginx -s reload
2、若master1有pod,先将master1设置维护状态,驱逐所有pod
当前主节点没Pod
[root@k8s-master1 nginx]# kubectl get pods -A -o wide |grep 192.168.21.120
3、下载新版本k8s,备份原来的程序文件,复制并覆盖新组件服务至新k8s目录,更新软链接
[root@k8s-master1 opt]# cp -rp kubernetes-v1.22.1 kubernetes-v1.22.5
[root@k8s-master1 opt]#
替换新版本的程序
[root@k8s-master1 bin]# cp -p kube-apiserver kube-scheduler kube-controller-manager kubectl /opt/kubernetes-v1.22.5
cp: overwrite ‘/opt/kubernetes-v1.22.5/kube-apiserver’? y
cp: overwrite ‘/opt/kubernetes-v1.22.5/kube-scheduler’? y
cp: overwrite ‘/opt/kubernetes-v1.22.5/kube-controller-manager’? y
cp: overwrite ‘/opt/kubernetes-v1.22.5/kubectl’? y
[root@k8s-master1 opt]# ls -ltr
total 16
drwx--x--x 4 root root 28 Oct 17 21:52 containerd
lrwxrwxrwx 1 root root 17 Oct 17 22:23 etcd -> /opt/etcd-v3.4.13
drwxr-xr-x 4 630384594 600260513 173 Oct 17 22:35 etcd-v3.4.13
drwxr-xr-x 3 root root 107 Oct 17 22:55 src
lrwxrwxrwx 1 root root 23 Oct 17 22:56 kubernetes -> /opt/kubernetes-v1.22.1
drwxr-xr-x 3 root root 4096 Nov 5 10:50 kubernetes-v1.22.5
drwxr-xr-x 3 root root 4096 Nov 5 10:50 kubernetes-v1.22.1
drwxr-xr-x 2 root root 52 Nov 5 20:06 dashboard
drwxr-xr-x 8 root root 4096 Nov 25 22:07 helm
drwxr-xr-x 2 root root 88 Jan 12 18:09 k8s-yaml
drwxr-xr-x 3 root root 4096 Jan 14 18:00 certs
[root@k8s-master1 opt]#
[root@k8s-master1 opt]#
[root@k8s-master1 opt]# ln -snf /opt/kubernetes-v1.22.5 /opt/kubernetes
[root@k8s-master1 opt]# ls -ltr
total 16
drwx--x--x 4 root root 28 Oct 17 21:52 containerd
lrwxrwxrwx 1 root root 17 Oct 17 22:23 etcd -> /opt/etcd-v3.4.13
drwxr-xr-x 4 630384594 600260513 173 Oct 17 22:35 etcd-v3.4.13
drwxr-xr-x 3 root root 107 Oct 17 22:55 src
drwxr-xr-x 3 root root 4096 Nov 5 10:50 kubernetes-v1.22.5
drwxr-xr-x 3 root root 4096 Nov 5 10:50 kubernetes-v1.22.1
drwxr-xr-x 2 root root 52 Nov 5 20:06 dashboard
drwxr-xr-x 8 root root 4096 Nov 25 22:07 helm
drwxr-xr-x 2 root root 88 Jan 12 18:09 k8s-yaml
drwxr-xr-x 3 root root 4096 Jan 14 18:00 certs
lrwxrwxrwx 1 root root 23 Jan 18 18:19 kubernetes -> /opt/kubernetes-v1.22.5
5、重启相关服务,检查版本是否正常
重启服务
[root@k8s-master1 opt]# systemctl restart kube-apiserver.service kube-scheduler.service kube-controller-manager.service
6、取消维护状态,启用nginx配置
7、其他节点一样重复操作
8.检查验证
[root@k8s-master1 nginx]# kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:38:33Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:32:32Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}