在现实中,往往会遇到集群节点资源紧张,这时候需要增加更多的节点来缓解,并且k8s会自动迁移一些容器到新的节点上,以保证各个节点压力均很,接下来利用 kubesphere 社区提供的集群安装工具 kubekey 来给集群增加新的 worker 节点。
现有的集群有三个节点,分别为master、node1、node2, 现在给集群扩容一个节点 node3,操作步骤如下所示。
创建新机器
集群用的 VM 虚拟机,系统centos7,先找一台干净的虚拟机克隆一台新机器,注意需要关闭VM后才能点击克隆。

配置网络
新克隆的虚拟机可能存在网络IP冲突,需要先配置一个新的IP地址,才能用xshell工具连接,按照如下步骤配置网络。
- 在vm窗口登录root账号

- 使用 nmtui 引导配置网络,在终端输入nmtui,具体步骤如下:


- 修改一个新的IP地址

- 保存后重启网络,如果没有任何输出说明ok。
1
|
systemctl restart newwork
|

- 然后就可以用 xshell 连接了,操作起来更加方便。

安装依赖
- 设置 hostname
1
|
hostnamectl set-hostnmae node3
|

- 设置时区
1
2
|
timedatectl set-timezone Asia/Shanghai
timedatectl
|

- 配置时间同步器
1
2
|
yum install -y chrony
systemctl restart chronyd && systemctl enable chronyd
|
- 配置集群所有节点 hosts , 把 node3 加入到 hosts配置文件中。

- 其他三个要修改的地方,和安装集群时操作一致,这里放在一起说明。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
1、关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
2、关闭 selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久关闭
setenforce 0 # 临时关闭
3、关闭 swap
swapoff -a # 临时关闭
vim /etc/fstab # 永久关闭
#注释掉swap这行
# /dev/mapper/centos-swap swap swap defaults 0 0
systemctl reboot #重启生效
free -m #查看下swap交换区是否都为0,如果都为0则swap关闭成功
|
- 安装依赖, 这是集群所必须依赖的软件。
1
2
3
4
|
# 安装 Kubernetes 系统依赖包
yum install curl socat conntrack ebtables ipset ipvsadm
# 安装其他必备包,openEuler 也是奇葩了,默认居然都不安装tar,不装的话后面会报错
yum install tar
|
执行扩容
- 在 master 节点找到安装集群时用的配置文件和kk工具。

- 执行 vim 修改配置文件,加入 node3 新节点的配置信息。

- 执行以下命令扩容,在检查通过后输入 yes
1
2
3
|
export KKZONE=cn
./kk add nodes -f config-sample.yaml
|

- 一段时间后看到如下结果表示扩容成功。

验证状态
- 查看集群的状态,发现node3已就绪。

- 登录到 kubesphere 控制台查看,部分节点已经自动迁移到 node3 上。


参考文档