集群打包Sealer全系列之四 -- 升级备份扩缩容 前言

image.png

前言

  上回对 Clusterfile 进行了详细对讲解,想必大家对 sealer 有更进一步的了解了,那么这篇文章我们聊聊集群备份扩缩容相关的知识。

1.扩缩容

1.1 ALI_CLOUD 模式扩缩容

  ALI_CLOUD 模式就是,provider: ALI_CLOUD

1.1.1 Clusterfile 配置扩缩容

  比如下面这个配置文件是你当前运行的集群 .sealer/my-cluster/ 路径下的 clusterfile 文件(当然你也可以重新写一个文件,然后覆盖运行中的文件):

  我们可以看到 master 节点上的 count 有3个,如果此时你想扩展节点,把 count 的节点数改成4;如果你想缩小节点,把 count 的节点数改成2,然后使用 apply 命令生效 clusterfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
yaml复制代码apiVersion: sealer.aliyun.com/v1alpha1
kind: Cluster
metadata:
name: my-cluster
spec:
 #集群镜像
image: registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.19.9
 #当前的集群模式
provider: ALI_CLOUD
network:
   # in use NIC name
  interface: eth0
   # Network plug-in name
  cniName: calico
  podCIDR: 100.64.0.0/10
  svcCIDR: 10.96.0.0/22
  withoutCNI: false
certSANS:
  - aliyun-inc.com
  - 10.0.0.2
   
masters:
  cpu: 4
  memory: 4
   #根据count的值进行缩容或者扩容
  count: 3
  systemDisk: 100
  dataDisks:
  - 100
nodes:
  cpu: 4
  memory: 4
   #根据count的值进行缩容或者扩容
  count: 3
  systemDisk: 100
  dataDisks:
  - 100

1.1.2 join 命令配置扩容,delete 缩容

  当然在这个模式下,你也可以用 join 命令扩缩容

1
2
3
4
5
css复制代码# 扩容
sealer join --masters 2 --nodes 3

# 缩容
sealer delete --masters 2 --nodes 3

1.2 BAREMETAL 模式扩缩容

  BAREMETAL 模式就是,provider: BAREMETAL

1.2.1 Clusterfile配置扩缩容

  比如下面这个配置文件是你当前运行的集群 .sealer/my-cluster/ 路径下的 clusterfile 文件(当然你也可以重新写一个文件,然后覆盖运行中的文件):

我们可以看到 master 节点上的 ipList 有三个,如果要缩小则删掉其中一个 ip,如果要增加,则加上一个ip,然后 apply 命令让 clusterfile 生效一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
yaml复制代码apiVersion: sealer.aliyun.com/v1alpha1
kind: Cluster
metadata:
name: my-cluster
spec:
 #集群镜像
image: registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.19.9
 #当前的集群模式
provider: BAREMETAL
ssh:
   # SSH login password, if you use the key to log in, you don’t need to set it
  passwd:
   ## The absolute path of the ssh private key file, for example /root/.ssh/id_rsa
  pk: xxx
   # The password of the ssh private key file, if there is none, set it to ""
  pkPasswd: xxx
   # ssh login user
  user: root
network:
   # in use NIC name
  interface: eth0
   # Network plug-in name
  cniName: calico
  podCIDR: 100.64.0.0/10
  svcCIDR: 10.96.0.0/22
  withoutCNI: false
certSANS:
  - aliyun-inc.com
  - 10.0.0.2
   
masters:
   #根据iplList的值缩容或者扩容
  ipList:
    - 172.20.126.4
    - 172.20.126.5
    - 172.20.126.6
nodes:
   #根据iplList的值缩容或者扩容
  ipList:
    - 172.20.126.8
    - 172.20.126.9
    - 172.20.126.10

1.2.2 join命令扩容,delete命令缩容

  当然,这个模式下也可以使用 join 命令进行扩容,delete 命令进行缩容

1
2
3
4
5
css复制代码# 扩容
sealer join --masters 192.168.0.2 --nodes 192.168.0.3

#缩容
sealer delete --masters 192.168.0.2 --nodes 192.168.0.3

二.备份恢复

  备份利用的是插件机制,kind:Plugin,如下例子 如果你的 yaml 中写了 oss 地址,那么会将你的备份文件上传到oss上去, 如果没有呢,默认是放到 $(rootfs)/plugin/ETCD_BACKUP file 路径下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
yaml复制代码---
apiVersion: sealer.aliyun.com/v1alpha1
kind: Plugin
metadata:
name: ETCD_BACKUP
spec:
action: Manual
 # 可以配置oss地址,进行备份存储
data: |
    alioss:
      ossendpoint: oss-cn-hangzhou.aliyuncs.com
      accesskeyid: *****
      accesskeysecrets: ****
      bucketname: etcdbackup
      objectpath: /sealos/

三.升级

  升级集群镜像使用如下命令

1
复制代码sealer upgrade

  upgrade命令的工作流程可以概括如下:

解析命令的参数 -> 执行 Apply() 函数 -> 执行 diff() 函数得到 todoList -> 执行 todoList 中的函数 -> 升级成功 -> 更新当前集群的Image变量值。

源码分析参考官方文档sealer upgrade 命令的原理与实现

结语

  好了,各位铁汁们,关于Clusterfile的详细内容,就介绍到这,更多信息请到sealer官方git地址上去了解。创作不易,请点个赞,点个关注,后续将分享更多有用信息。

推荐阅读

微信公众号

image.png

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%