k8s单机变成集群

  • 携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第2天,点击查看活动详情

前言

image.png

在上一篇中搭建了单机的k8s和它的管理系统KubeSphere,但是在实际应用中肯定不是`All-in-One`形式的。

所以要在目前单机的基础上添加工作节点形成集群,默认我们上一篇安装的就是master节点,在master节点的基础上增加node节点

复制代码

node节点环境配置

工作节点对于硬件环境的依赖没有太强,本篇的其中一个工作节点为1C2G,算是将近最低的配置了,但是软件都需要进行安装,否则在脚本执行时会报错缺乏所需软件,软件环境的配置跟之前的操作一样,不过不需要安装kubkey,下面进行软件环境的安装。

第一步: 关闭防火墙

systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
复制代码

第二步:关闭swap分区

swapoff -a
echo "vm.swappiness=0" >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf
复制代码

第三步:配置epel源

rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
复制代码

第四步:更新yum

yum -y update
复制代码

第五步:安装依赖组件

yum install -y ebtables socat ipset conntrack
复制代码

第六步:修改hostaname

这里的名称根据不同的node节点进行修改,node1 - node*

hostnamectl --static set-hostname node1
复制代码

master节点配置集群

第一步:创建配置文件

使用 KubeKey 检索集群信息。执行以下命令创建配置文件 (sample.yaml)。

./kk create config --from-cluster
复制代码

第二步:修改配置文件

在配置文件中,将新节点的信息放在 hosts 和 roleGroups 之下。但是要在第一行加入master节点

apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  ##You should complete the ssh information of the hosts
  - {name: master, address: 10.0.20.8, internalAddress: 10.0.20.8}
  - {name: node1, address: 10.0.20.9, internalAddress: 10.0.20.9, user: root, password: xxx}
  - {name: node2, address: 10.0.20.10, internalAddress: 10.0.20.10, user: root, password: xxx}
  - {name: node3, address: 10.0.20.11, internalAddress: 10.0.20.11, user: root, password: xxx}
  roleGroups:
    etcd:
    - master
    master:
    - master
    worker:
    - node1
    - node2
    - node3
  controlPlaneEndpoint:
    ##Internal loadbalancer for apiservers
    #internalLoadbalancer: haproxy

    ##If the external loadbalancer was used, 'address' should be set to loadbalancer's ip.
    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.22.10
    clusterName: cluster.local
    proxyMode: ipvs
    masqueradeAll: false
    maxPods: 110
    nodeCidrMaskSize: 24
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18

复制代码

只要设置hostsroleGroups的参数就可以

第三步:执行安装命令

执行以下命令进行安装

./kk add nodes -f sample.yaml
复制代码

第四步:等待安装

`此次安装过程较长,摸个鱼吧`
复制代码

第五步:完成核验

安装完成后,可以在 KubeSphere 的控制台上查看新节点及其信息。在集群管理页面,选择左侧菜单节点下的集群节点,或者执行命令 kubectl get node 以检查更改。

  • 命令核验:

image.png

  • 页面核验:

image.png

在页面及命令中都可以看到三个节点已经组成了集群,但是我实际配置了三台工作节点。 有一台因为是非同区域外网导致iptable无法映射没有加入成功到集群节点中,后面我尝试配置内外网映射将外网服务器加入到集群中

猜你喜欢

转载自juejin.im/post/7125727632959733797