You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需Heketi服务器,如何在Kubernetes中使用外部GlusterFS?

在Kubernetes中不依赖Heketi使用外部GlusterFS集群的方案

如果你已经有一套正常运行的GlusterFS集群,要在Kubernetes中跳过Heketi直接对接,最可靠的方案是静态PersistentVolume(PV)+ Endpoints的方式,不需要额外依赖任何中间服务,步骤如下:

1. 提前在GlusterFS集群中创建好目标卷

先在你的Gluster集群节点上创建需要的卷(比如纠删码卷),示例命令如下:

# 创建纠删码卷(根据你的集群节点数调整stripe、replica参数和brick路径)
gluster volume create gfs-ec-volume erasure-code stripe 4 replica 2 transport tcp \
  node1:/bricks/ec1 \
  node2:/bricks/ec2 \
  node3:/bricks/ec3 \
  node4:/bricks/ec4 \
  node5:/bricks/ec5 \
  node6:/bricks/ec6

# 启动卷
gluster volume start gfs-ec-volume

# 验证卷状态
gluster volume info gfs-ec-volume

确保卷处于Started状态,且所有brick正常在线。

2. 在Kubernetes中配置GlusterFS Endpoints

Endpoints用于让Kubernetes集群定位到GlusterFS的节点,创建glusterfs-endpoints.yaml:

apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: 192.168.1.10  # 替换为你的Gluster节点1的IP
  - ip: 192.168.1.11  # 替换为你的Gluster节点2的IP
  - ip: 192.168.1.12  # 替换为你的Gluster节点3的IP
  ports:
  - port: 24007
    protocol: TCP

执行创建命令:

kubectl apply -f glusterfs-endpoints.yaml

3. 创建静态PersistentVolume(PV)

将已有的Gluster卷映射为Kubernetes的PV,创建glusterfs-pv.yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-ec-pv
spec:
  capacity:
    storage: 10Gi  # 匹配Gluster卷的实际可用容量
  accessModes:
    - ReadWriteMany  # GlusterFS原生支持多节点读写
  glusterfs:
    endpoints: glusterfs-cluster
    path: gfs-ec-volume  # 替换为你创建的Gluster卷名称
    readOnly: false
  persistentVolumeReclaimPolicy: Retain  # 删除PVC后保留PV和Gluster卷

执行创建命令:

kubectl apply -f glusterfs-pv.yaml

4. 创建PersistentVolumeClaim(PVC)并挂载到Pod

创建PVC来绑定上面的PV,glusterfs-pvc.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-ec-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi  # 不超过PV的容量

执行创建:

kubectl apply -f glusterfs-pvc.yaml

最后在Pod中挂载该PVC,示例glusterfs-pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-gluster-demo
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    volumeMounts:
    - name: gluster-storage
      mountPath: /usr/share/nginx/html
  volumes:
  - name: gluster-storage
    persistentVolumeClaim:
      claimName: glusterfs-ec-pvc

注意事项

  • 确保Kubernetes所有节点能访问Gluster集群的节点,开放端口:24007(Gluster管理端口)、24008(Gluster客户端端口),以及brick使用的动态端口范围(默认49152-49251)。
  • 纠删码卷的参数(stripe、replica)需要根据你的Gluster集群节点数和存储需求调整,遵循Gluster官方的纠删码配置规则。
  • 如果需要动态创建卷,目前没有官方的替代Heketi的方案,建议通过脚本自动化Gluster卷创建和PV生成的流程,避免手动操作的繁琐。

内容的提问来源于stack exchange,提问作者Venkat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 21:35:19