What is the correct volume type to use for persistent data in Kubernetes?

3/15/2017

I'm setting up Jenkins on kubernetes. My current deployment looks like this:

    spec:
        containers:
            - name: jenkins-master
              image: jenkins:1.0
              ports:
                  - containerPort: 8080
                    name: http
              volumeMounts:
                  - mountPath: /var/jenkins_home
                    name: jenkins-home
        volumes:
            - name: jenkins-home
              emptyDir: {}

It works fine, but the data disappears if the pod gets destroyed, because the folder that jenkins uses to store data is mounted as an emptyDir, which means the data lives as long as the pod lives.

This is obviously not an optimal scenario, since the pod can be destroyed for many reasons, even during normal operations. I know I have to replace the emptyDir with something else, however, I'm not sure what should I use. I could provision a GCE disk, however, if you provision a disk under 200GB, you get a warning that your disk will be throttled. Since GCE disks can only by claimed by one writer at the time, it seems overkill, we would end up with an expensive bill if I used a GCE disk for every service that needs to hold persistent data.

To generalize the question:

You run several services on kubernetes, that need to hold a small amount of persistent, on-disk, data. What kind of storage do you provision for them?

-- K. Norbert
jenkins
kubernetes

1 Answer

3/15/2017

What you're looking for is Persistent Volumes which essentially model an underlying persistent volume (say, AWS EBS or OpenStack Cinder volume) as resource.

This resource, named simply PersistentVolume defines the specification for the volume including e.g. its size and name. To actually use it you need to add PersistentVolumeClaim to your deployment yml which defines what your deployment expects from the persistent volume you want to attach to it - it is possible to have multiple matching persistent volumes for each claim just as it is possible that there won't be any volumes left to claim which is why this distinction exists.

-- Esko
Source: StackOverflow