k8s中使用glusterfs
靜態手動管理glusterfs
這種方式是手動管理volume。假設在k8s上部署一個使用gluster存儲的應用,如果使用之前應用的volume,能看到其他應用的數據,多個應用之間的數據應該是隔離的,也就是權限問題,同時,大概率導致文件命名沖突問題。pv(c)中設置的容量capacity也無法控制。基本上處於不可用。
通過heketi來動態管理glusterfs
- heketi調度分配gluster的存儲調度算法
- 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過程中遇到的一些問題記錄一下:
-
mount: permission denied
a: docker啟動的時候加上參數 --privileged=true,也可以在k8s 的yaml文件中配置該項
-
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這種方式
-
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,使配置生效 -
Can't open /dev/sdb exclusively. Mounted filesystem?
a: heketi只管理沒有文件系統的裸盤,如果你的機器上的磁盤的文件系統是xfs或者是ext4,可以執行
pvcreate --metadatasize=128M --dataalignment=256K /dev/sdb
將磁盤格式化成LVM2形式,那么就沒問題了,這個問題困擾了我好久 -
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共享存儲
轉載請標明出處