初始化
-
安装好的 Kubernetes 集群,其中三个节点应各挂载一块空间不小于 500G 的 SSD 磁盘
-
将准备好的磁盘格式化并挂载到指定目录,需要在所有作为glusterfs master节点执行
# 查看可用磁盘
fdisk -l
# 分区并格式化
mkfs.xfs /dev/vdb
mkdir -p /data
echo "/dev/vdb /data xfs defaults 1 2" >>/etc/fstab
# 挂载
mount -a
# 确定/data挂载
df -h | grep data
- 在 Kubernetes 所有节点安装对应版本的 Glusterfs 客户端工具并加载所需内核模块
# debian 系
apt install software-properties-common
add-apt-repository ppa:gluster/glusterfs-7
apt update
apt install glusterfs-client -y
modprobe dm_thin_pool
apt-get -y install glusterfs-server
systemctl stop glusterd
systemctl disable glusterd
#centos 系
yum -y install centos-release-gluster
yum -y install glusterfs-server
systemctl stop glusterd
systemctl disable glusterd
# kylin os
yum -y install glusterfs
systemctl stop glusterd
systemctl disable glusterd
设置glusterfs标签
#设置标签,将 Glusterfs1/2/3 更改为对应的 Kubernetes node 节点IP
kubectl label node Glusterfs1 Glusterfs2 Glusterfs3 storagenode=glusterfs
glusterfs节点不允许调度
kubectl taint node Glusterfs1 Glusterfs2 Glusterfs3 glusterfs=true:NoSchedule
创建glusterfs服务
# ARM
git clone https://gitee.com/JokerPom/gfs-k8s-arm.git cd gfs-k8s-arm
# x86
git clone https://gitee.com/liu_shuai2573/gfs-k8s.git && cd gfs-k8s
检查 Glusterfs 服务是否在指定节点正常运行
kubectl get pods -o wide --selector=glusterfs-node=daemonset
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
glusterfs-2k5rm 1/1 Running 0 52m 192.168.2.200 192.168.2.200 <none> <none>
glusterfs-mc6pg 1/1 Running 0 134m 192.168.2.22 192.168.2.22 <none> <none>
glusterfs-tgsn7 1/1 Running 0 134m 192.168.2.224 192.168.2.224 <none> <none>
添加集群
#通过其中一个 Glusterfs 服务将其他两个 Glusterfs 服务加入集群
kubectl exec -ti glusterfs-2k5rm gluster peer probe Glusterfs2_IP
kubectl exec -ti glusterfs-2k5rm gluster peer probe Glusterfs3_IP
#检测是否添加成功,添加成功会显示其他两个 Glusterfs 服务的状态
kubectl exec -ti glusterfs-2k5rm gluster peer status
配置 Glusterfs 集群为 Kubernetes 的可使用资源
#创建服务账户并进行 RBAC 授权
kubectl create -f rbac.yaml
#创建 Glusterfs-provisioner
kubectl create -f deployment.yaml
# 创建storageclass资源, 需要修改 storageclass.yaml 中的 parameters.brickrootPaths 的值,替换为 Glusterfs 节点的IP
kubectl create -f storageclass.yaml