How does PersistentVolume work with hostPath?

1/23/2017

I have deployed Gitlab to my azure kubernetes cluster with a persistant storage defined the following way:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: gitlab-data
  namespace: gitlab
spec:
  capacity:
    storage: 8Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/tmp/gitlab-data"

That worked fine for some days. Suddenly all my data stored in Gitlab is gone and I don't know why. I was assuming that the hostPath defined PersistentVolumen is really persistent, because it is saved on a node and somehow replicated to all existing nodes. But my data now is lost and I cannot figure out why. I looked up the uptime of each node and there was no restart. I logged in into the nodes and checked the path and as far as I can see the data is gone.

So how do PersistentVolume Mounts work in Kubernetes? Are the data saved really persistent on the nodes? How do multiple nodes share the data, if a deployment is split to multiple nodes? Is hostPath reliable persistent storage?

-- Jan Hommes
azure
gitlab
kubernetes

1 Answer

1/23/2017

hostPath doesn't share or replicate data between nodes and once your pod starts on another node, the data will be lost. You should consider to use some external shared storage.

Here's the related quote from the official docs:

HostPath (single node testing only – local storage is not supported in any way and WILL NOT WORK in a multi-node cluster)

from kubernetes.io/docs/user-guide/persistent-volumes/

-- pagid
Source: StackOverflow