<p>I am using GlusterFS volume plugin in my Kubernetes cluster on a Ubuntu installed GlusterFS using DaemonSet.</p>
<p>My dought is how the data is mounted? Are PVCs or PVs replicated on every kubernetes worker or the disks which are configured in topology.json for every worker node sharable amoung the cluster? I read the documents, but I didn't get clarity.</p>
<p>How the GlusterFS works?</p>

BSG
<p>Here is the <a href="https://github.com/gluster/gluster-kubernetes" rel="nofollow noreferrer">link</a> to the official GlusteFS for Kubernetes repository. Two main components are used in this approach: GlusterFS itself and Heketi.</p>

<p><strong>GlusterFS</strong> is a scalable, distributed file system that aggregates disk storage resources from multiple servers into a single global namespace. A Volume in GlusterFS consists of blocks called Bricks. Bricks are located on a different server according to a type of the Volume, there are several types of volumes and for more information about them, you can visit <a href="https://docs.gluster.org/en/latest/Quick-Start-Guide/Architecture/" rel="nofollow noreferrer">this link</a>.</p>

<p><strong>Heketi</strong> provides an interface which can be used to manage the lifecycle of GlusterFS volumes. Heketi is used in Kubernetes for a dynamically provision GlusterFS volumes. </p>

<p>In the example from the repository, 3 Nodes for GlusterFS are used, each Node has block devices. All that is mentioned in <code>topology.json</code> file for Heketi:</p>

<pre><code>{
  "clusters": [
    {
      "nodes": [
        {
          "node": {
            "hostnames": {
              "manage": [
                "node0"
              ],
              "storage": [
                "192.168.10.100"
              ]
            },
            "zone": 1
          },
          "devices": [
            "/dev/vdb",
            "/dev/vdc",
            "/dev/vdd"
          ]
        },
        {
          "node": {
            "hostnames": {
              "manage": [
                "node1"
              ],
              "storage": [
                "192.168.10.101"
              ]
            },
            "zone": 1
          },
          "devices": [
            "/dev/vdb",
            "/dev/vdc",
            "/dev/vdd"
          ]
        },
        {
          "node": {
            "hostnames": {
              "manage": [
                "node2"
              ],
              "storage": [
                "192.168.10.102"
              ]
            },
            "zone": 1
          },
          "devices": [
            "/dev/vdb",
            "/dev/vdc",
            "/dev/vdd"
          ]
        }
      ]
    }
  ]
}
</code></pre>

<p>These Nodes are Kubernetes Nodes as well, you can use all your Kubernetes Nodes as servers for GlusterFS, but the minimum number of Nodes is three.</p>

<p>Heketi will format the block devices posted in <code>topology.json</code> file and include them into GlusterFS cluster. </p>

<p>After that, you need to create a Kuberntes StorageClass for dynamic provision of GlusterFS volumes. Example of a Yaml file for Kubernetes:</p>

<pre><code>apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
  name: gluster-heketi
provisioner: kubernetes.io/glusterfs
parameters: #Here are the setting for access to Heketi RESTapi
  resturl: "http://10.42.0.0:8080" 
  restuser: "joe" 
  restuserkey: "My Secret Life"  
</code></pre>

<p>Now you can create a PersistentVolumeClaim with a request to the StorageClass. This action will trigger three processes:<br>
1. Kubernetes will create a GlusterFS Volume using Heketi<br>
2. Kubernetes will create a PersistentVolume configured to use the GlusterFS Volume<br>
3. Kubernetes will assign the PersistentVolume to the PersistentVolumeClaim</p>

<p>Here is the example:</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: gluster1
 annotations:
   volume.beta.kubernetes.io/storage-class: gluster-heketi 
spec:
 accessModes:
  - ReadWriteOnce
 resources:
   requests:
     storage: 5Gi
</code></pre>

<p>After that, you can use the PersistentVolumeClaim in Kubernetes Deployments, Pods and etc. The example of the Pod configuration:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod1
  labels:
    name: nginx-pod1
spec:
  containers:
  - name: nginx-pod1
    image: gcr.io/google_containers/nginx-slim:0.8
    ports:
    - name: web
      containerPort: 80
    volumeMounts:
    - name: gluster-vol1
      mountPath: /usr/share/nginx/html
  volumes:
  - name: gluster-vol1
    persistentVolumeClaim:
      claimName: gluster1 &lt;1&gt;
</code></pre>

<p>For more information, you can look through this example on the <a href="https://github.com/gluster/gluster-kubernetes/blob/master/docs/examples/hello_world/README.md" rel="nofollow noreferrer">link</a>.</p>
