27.3.6. 置备


GlusterFS 卷可以静态或动态置备。静态置备适用于所有配置。只有聚合模式和独立模式支持动态置备。

27.3.6.1. 静态置备

  1. 要启用静态置备,首先请创建一个 GlusterFS 卷。请参阅 Red Hat Gluster Storage Administration Guide 了解如何使用 gluster 命令行的信息;请参阅 heketi 项目网站来了解如何使用 heketi-cli 的信息。在本例中,卷将命名为 myVol1
  2. gluster-endpoints.yaml 中定义以下服务和端点:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: glusterfs-cluster 
    1
    
    spec:
      ports:
      - port: 1
    ---
    apiVersion: v1
    kind: Endpoints
    metadata:
      name: glusterfs-cluster 
    2
    
    subsets:
      - addresses:
          - ip: 192.168.122.221 
    3
    
        ports:
          - port: 1 
    4
    
      - addresses:
          - ip: 192.168.122.222 
    5
    
        ports:
          - port: 1 
    6
    
      - addresses:
          - ip: 192.168.122.223 
    7
    
        ports:
          - port: 1 
    8
    Copy to Clipboard Toggle word wrap
    1 2
    这些名称必须匹配。
    3 5 7
    ip 值必须是 Red Hat Gluster Storage 服务器的实际 IP 地址,而不是主机名。
    4 6 8
    端口号被忽略。
  3. 在 OpenShift Container Platform master 主机上创建服务和端点:

    $ oc create -f gluster-endpoints.yaml
    service "glusterfs-cluster" created
    endpoints "glusterfs-cluster" created
    Copy to Clipboard Toggle word wrap
  4. 验证服务和端点是否已创建:

    $ oc get services
    NAME                       CLUSTER_IP       EXTERNAL_IP   PORT(S)    SELECTOR        AGE
    glusterfs-cluster          172.30.205.34    <none>        1/TCP      <none>          44s
    
    $ oc get endpoints
    NAME                ENDPOINTS                                               AGE
    docker-registry     10.1.0.3:5000                                           4h
    glusterfs-cluster   192.168.122.221:1,192.168.122.222:1,192.168.122.223:1   11s
    kubernetes          172.16.35.3:8443                                        4d
    Copy to Clipboard Toggle word wrap
    注意

    端点每个项目都是唯一的。访问 GlusterFS 卷的每个项目都需要自己的端点。

  5. 若要访问卷,容器必须使用用户 ID(UID)或组 ID(GID)运行,该容器有权访问卷上的文件系统。这些信息可以通过以下方法发现:

    $ mkdir -p /mnt/glusterfs/myVol1
    
    $ mount -t glusterfs 192.168.122.221:/myVol1 /mnt/glusterfs/myVol1
    
    $ ls -lnZ /mnt/glusterfs/
    drwxrwx---. 592 590 system_u:object_r:fusefs_t:s0    myVol1 
    1
     
    2
    Copy to Clipboard Toggle word wrap
    1
    UID 为 592。
    2
    GID 是 590。
  6. gluster-pv.yaml 中定义以下 PersistentVolume(PV):

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: gluster-default-volume 
    1
    
      annotations:
        pv.beta.kubernetes.io/gid: "590" 
    2
    
    spec:
      capacity:
        storage: 2Gi 
    3
    
      accessModes: 
    4
    
        - ReadWriteMany
      glusterfs:
        endpoints: glusterfs-cluster 
    5
    
        path: myVol1 
    6
    
        readOnly: false
      persistentVolumeReclaimPolicy: Retain
    Copy to Clipboard Toggle word wrap
    1
    卷的名称。
    2
    GlusterFS 卷根上的 GID。
    3
    为这个卷分配的存储量。
    4
    accessModes 用作标签,以匹配 PV 和 PVC。它们目前没有定义任何形式的访问控制。
    5
    之前创建的 Endpoints 资源。
    6
    将要访问的 GlusterFS 卷。
  7. 在 OpenShift Container Platform master 主机上创建 PV:

    $ oc create -f gluster-pv.yaml
    Copy to Clipboard Toggle word wrap
  8. 确定创建了 PV:

    $ oc get pv
    NAME                     LABELS    CAPACITY     ACCESSMODES   STATUS      CLAIM     REASON    AGE
    gluster-default-volume   <none>    2147483648   RWX           Available                       2s
    Copy to Clipboard Toggle word wrap
  9. 创建一个 PersistentVolumeClaim(PVC),它将绑定到 gluster-claim.yaml 中的新 PV:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: gluster-claim  
    1
    
    spec:
      accessModes:
      - ReadWriteMany      
    2
    
      resources:
         requests:
           storage: 1Gi    
    3
    Copy to Clipboard Toggle word wrap
    1
    声明名称由 pod 在其 volumes 部分下引用。
    2
    必须与 PV 的 accessModes 匹配。
    3
    这个声明会查找提供 1Gi 或更高容量的 PV。
  10. 在 OpenShift Container Platform master 主机上创建 PVC:

    $ oc create -f gluster-claim.yaml
    Copy to Clipboard Toggle word wrap
  11. 验证 PV 和 PVC 是否已绑定:

    $ oc get pv
    NAME         LABELS    CAPACITY   ACCESSMODES   STATUS      CLAIM          REASON    AGE
    gluster-pv   <none>    1Gi        RWX           Available   gluster-claim            37s
    
    $ oc get pvc
    NAME            LABELS    STATUS    VOLUME       CAPACITY   ACCESSMODES   AGE
    gluster-claim   <none>    Bound     gluster-pv   1Gi        RWX           24s
    Copy to Clipboard Toggle word wrap
注意

PVC 每个项目都是唯一的。访问 GlusterFS 卷的每个项目都需要自己的 PVC。PV 不绑定到单个项目,因此多个项目的 PVC 可能会引用同一 PV。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat