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

<pre><code>    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: {}
</code></pre>

<p>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 <code>emptyDir</code>, which means the data lives as long as the pod lives.</p>

<p>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 <code>emptyDir</code> 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. </p>

<p>To generalize the question:</p>

<p>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?</p>

<p>What you're looking for is <a href="https://kubernetes.io/docs/user-guide/persistent-volumes/" rel="nofollow noreferrer">Persistent Volumes</a> which essentially model an underlying persistent volume (<em>say, AWS EBS or OpenStack Cinder volume</em>) as resource.</p>

<p>This resource, named simply <a href="https://kubernetes.io/docs/user-guide/persistent-volumes/#persistent-volumes" rel="nofollow noreferrer"><code>PersistentVolume</code></a> defines the specification for the volume including e.g. its size and name. To actually use it you need to add <a href="https://kubernetes.io/docs/user-guide/persistent-volumes/#persistentvolumeclaims" rel="nofollow noreferrer"><code>PersistentVolumeClaim</code></a> to your deployment yml which defines what your deployment <em>expects</em> 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.</p>
