k8s由1.20升级到1.21

etcd的升级

查看版本

使用

~]# etcdctl version
1
2
3
[root@m1 ~]# etcdctl version
etcdctl version: 3.4.14
API version: 3.4

或者

1
2
[root@m1 ~]# curl http://localhost:2379/version
{"etcdserver":"3.4.14","etcdcluster":"3.4.0"}

检查当前的集群是否健康

1
2
3
4
5
6
7
8
9
[root@m1 pki]# etcdctl \
> --endpoints="https://192.168.242.101:2379,https://192.168.242.102:2379,https://192.168.242.103:2379" \
> --cacert=/root/k8s-install/pki/ca.pem \
> --key=/root/k8s-install/pki/etcd-key.pem \
> --cert=/root/k8s-install/pki/etcd.pem \
> endpoint health
https://192.168.242.102:2379 is healthy: successfully committed proposal: took = 13.250166ms
https://192.168.242.101:2379 is healthy: successfully committed proposal: took = 12.929533ms
https://192.168.242.103:2379 is healthy: successfully committed proposal: took = 14.849421ms

备份数据

1
2
3
4
5
6
7
8
[root@m1 pki]# etcdctl snapshot save backup.db
{"level":"info","ts":1619073403.356036,"caller":"snapshot/v3_snapshot.go:119","msg":"created temporary db file","path":"backup.db.part"}
{"level":"info","ts":"2021-04-22T14:36:43.356+0800","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"}
{"level":"info","ts":1619073403.3566058,"caller":"snapshot/v3_snapshot.go:127","msg":"fetching snapshot","endpoint":"127.0.0.1:2379"}
{"level":"info","ts":"2021-04-22T14:36:43.460+0800","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"}
{"level":"info","ts":1619073403.4815285,"caller":"snapshot/v3_snapshot.go:142","msg":"fetched snapshot","endpoint":"127.0.0.1:2379","size":"16 MB","took":0.12544409}
{"level":"info","ts":1619073403.4815943,"caller":"snapshot/v3_snapshot.go:152","msg":"saved","path":"backup.db"}
Snapshot saved at backup.db

停止进程

1
[root@m1 pki]# systemctl stop etcd

下载新版本并安装

启动程序查看是否安装完成

1
2
3
[root@m1 bin]# etcdctl version
etcdctl version: 3.4.15
API version: 3.4

查看集群的健康状态

1
2
3
4
5
6
7
8
9
[root@m1 pki]# etcdctl \
> --endpoints="https://192.168.242.101:2379,https://192.168.242.102:2379,https://192.168.242.103:2379" \
> --cacert=/root/k8s-install/pki/ca.pem \
> --key=/root/k8s-install/pki/etcd-key.pem \
> --cert=/root/k8s-install/pki/etcd.pem \
> endpoint health
https://192.168.242.101:2379 is healthy: successfully committed proposal: took = 13.891029ms
https://192.168.242.102:2379 is healthy: successfully committed proposal: took = 12.852979ms
https://192.168.242.103:2379 is healthy: successfully committed proposal: took = 16.964588ms

至此,etcd集群升级完成,etcd应该可以进行数据同步,所以即使停止了etcd的进程一个一个升级问题应该不大。

k8s的升级

to be continued