<p>Yes, the <code>PersistentVolumeClaim</code> is the workhorse here. You can evict pods, delete deployments, etc., to your heart's content and so long as you don't delete the PVC, your data will be there.  </p>

<p>You don't need to use <code>StatefulSet</code> for this.  From the docs:</p>

<pre><code>Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.
</code></pre>

<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/</a></p>

<p>You might want that anyway, but it does nothing for keeping your PV/PVCs around.</p>

CC BY-SA 4.0
2019-11-25T14:51:04.307Z
2019-11-25T14:51:04.307Z
Matthew
<p>Let's say that you wanted to create a Jenkins <code>Deployment</code>. As Jenkins uses a local XML file for configuration and state, you would want to create a <code>PersistentVolume</code> so that your data could be saved across <code>Pod</code> evictions and <code>Deployment</code> deletions. I know that the <code>Retain</code> <code>reclaimPolicy</code> will result in the data persisting on the detached <code>PersistentVolume</code>, but the documentation says this is just so that you can manually reclaim the data on it later on, and seems to say nothing about the volume being automatically reused if its mounting <code>Pod</code>s are ever brought back up.</p>

<p>It is difficult to articulate what I am even trying to ask, so forgive me if this seems like a nebulous question, but:</p>

<ul>
<li>If you delete the Jenkins deployment, then later decide to recreate it where you left off, how do you get it to re-mount <em>that exact PersistentVolume</em> on which <em>that specific XML configuration</em> is still stored?</li>
<li>Is this a case where you would want to use a <code>StatefulSet</code>? It seems like, in this case, Jenkins would be considered "stateful."</li>
<li>Is the <code>PersistentVolumeClaim</code> the basis of a volume's "identity"? In other words, is the expectation for the <code>PersistentVolumeClaim</code> to be the stable identifier by which an application can bind to a specific volume with specific data on it?</li>
</ul>

<kubernetes><kubernetes-volume>
How do you reuse a specific volume in Kubernetes?
Jonathan Wilbur
# How do you reuse a specific volume in Kubernetes?

(Asked by: username_0 on 2019-11-24)

Let's say that you wanted to create a Jenkins `Deployment`. As Jenkins uses a local XML file for configuration and state, you would want to create a `PersistentVolume` so that your data could be saved across `Pod` evictions and `Deployment` deletions. I know that the `Retain` `reclaimPolicy` will result in the data persisting on the detached `PersistentVolume`, but the documentation says this is just so that you can manually reclaim the data on it later on, and seems to say nothing about the volume being automatically reused if its mounting `Pod`s are ever brought back up.

It is difficult to articulate what I am even trying to ask, so forgive me if this seems like a nebulous question, but:

* If you delete the Jenkins deployment, then later decide to recreate it where you left off, how do you get it to re-mount *that exact PersistentVolume* on which *that specific XML configuration* is still stored?
* Is this a case where you would want to use a `StatefulSet`? It seems like, in this case, Jenkins would be considered "stateful."
* Is the `PersistentVolumeClaim` the basis of a volume's "identity"? In other words, is the expectation for the `PersistentVolumeClaim` to be the stable identifier by which an application can bind to a specific volume with specific data on it?

**Tags:** kubernetes, kubernetes-volume


---

## 1 answers

### Answer by username_1 on 2019-11-25. Score: 2

Yes, the PersistentVolumeClaim is the workhorse here. You can evict pods, delete deployments, etc., to your heart's content and so long as you don't delete the PVC, your data will be there.  
You don't need to use StatefulSet for this.  From the docs:
Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.

https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
You might want that anyway, but it does nothing for keeping your PV/PVCs around.


---

