k8s中使用glusterfs

k8s中使用glusterfs

静态手动管理glusterfs

  1. 直接通过 brickrootPaths: "172.16.2.131:/tmp/,172.16.2.132:/tmp"'

  2. 通过"endpoints": "glusterfs-cluster",path": "kube_vol",

  3. 手动创建pvc,这种方式提示手动创建storageclass,但是只有动态创建的storageclass

这种方式是手动管理volume。假设在k8s上部署一个使用gluster存储的应用,如果使用之前应用的volume,能看到其他应用的数据,多个应用之间的数据应该是隔离的,也就是权限问题,同时,大概率导致文件命名冲突问题。pv(c)中设置的容量capacity也无法控制。基本上处于不可用。

通过heketi来动态管理glusterfs

  • heketi调度分配gluster的存储调度算法

存储调度算法Ring-Allocator

  • pv 回收策略

The deletion of the PV is done via the Kubernetes reclaim policy, which by default deletes the PV when the claim is no longer valid (thereby deleting the data, making it irrecoverable). This policy can be dealt with via the persistentVolumeReclaimPolicy field. The default value is nice because it results in Kubernetes garbage collecting our unused volumes, saving us from wasted space across the cluster.

通过heketi 提供的一些列REST API接口来动态管理gluster集群。

实现方式为:通过lvcreate命令创建一个逻辑卷(logical volume)lv1,mkfs.xfs格式化为xfs格式,然后挂载到路径/var/lib/heketi/mounts/卷组name/lv1并写入到/etc/fstab中,确保开机自动挂载。

这种方式的好处是1.实现了不同应用之间的数据的隔离性2.pvc中的capacity做到了限制。推荐使用。

QA

在使用heketi过程中遇到的一些问题记录一下:

  1. mount: permission denied

    a: docker启动的时候加上参数 --privileged=true,也可以在k8s 的yaml文件中配置该项

  2. could not open the file /proc/sys/net/ipv4/ip_local_reserved_ports for getting reserved ports info [No such file or directory] Not able to get reserved ports, hence there is a possibility that glusterfs may consume reserved port

    a: 这种错误是我在使用mock这种方式的时候出现的,通过heketi-cli 命令可以看到volume确实存在,可是在gluster 集群中却看不到,很坑,后来我采用了ssh这种方式

  3. Unable to add device: Device /bricks/heketi001 not found (or ignored by filtering)

    a: 首先确保device存在,然后在文件/etc/lvm/lvm.conf中将filter = [ "a|.*/|" ]取消掉注释,运行接受所有block,然后systemctl restart lvm2-lvmetad.service重启lvm,使配置生效

  4. Can't open /dev/sdb exclusively. Mounted filesystem?

    a: heketi只管理没有文件系统的裸盘,如果你的机器上的磁盘的文件系统是xfs或者是ext4,可以执行pvcreate --metadatasize=128M --dataalignment=256K /dev/sdb将磁盘格式化成LVM2形式,那么就没问题了,这个问题困扰了我好久

  5. heketi服务启动不了怎么办

    a: 设置环境变量HEKETI_IGNORE_STALE_OPERATIONS=true,然后再启动

cmd

列一些过程中常用的一些命令

fdisk -l /dev/sdb

lsblk

lvdisplay

lvs

lvrecreate/lvremove

lvm

lvmconfig

vgs

lvs

参考资料

persistent-volumes-with-glusterfs

独立部署GlusterFS+Heketi实现Kubernetes共享存储

heketi troubleshooting

heketi issue

猜你喜欢

转载自www.cnblogs.com/yourarebest/p/9629521.html