<p>I have a dynamic <code>PersistentVolume</code> provisioned using <code>PersistentVolumeClaim</code>.</p>
<p>I would like to keep the PV after the pod is done. So I would like to have what <code>persistentVolumeReclaimPolicy: Retain</code> does.</p>
<p>However, that is applicable to <code>PersistentVolume</code>, not <code>PersistentVolumeClaim</code> (AFAIK).</p>
<p><strong>How can I change this behavior for dynamically provisioned PV's?</strong></p>
<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
    name: {{ .Release.Name }}-pvc
spec:
    accessModes:
      - ReadWriteOnce
    storageClassName: gp2
    resources:
        requests:
            storage: 6Gi

---
kind: Pod
apiVersion: v1
metadata:
    name: &quot;{{ .Release.Name }}-gatling-test&quot;
spec:
    restartPolicy: Never
    containers:
      - name: {{ .Release.Name }}-gatling-test
        image: &quot;.../services-api-mvn-builder:latest&quot;
        command: [&quot;sh&quot;, &quot;-c&quot;, 'mvn -B gatling:test -pl csa-testing -DCSA_SERVER={{ template &quot;project.fullname&quot; . }} -DCSA_PORT={{ .Values.service.appPort }}']
        volumeMounts:
          - name: &quot;{{ .Release.Name }}-test-res&quot;
            mountPath: &quot;/tmp/testResults&quot;

    volumes:
      - name: &quot;{{ .Release.Name }}-test-res&quot;
        persistentVolumeClaim:
          claimName: &quot;{{ .Release.Name }}-pvc&quot;
          #persistentVolumeReclaimPolicy: Retain  ???
</code></pre>

<p>This is not the answer to the OP, but the answer to the personal itch that led me here is that I don't need <code>reclaimPolicy: Retain</code> at all. I need a <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/" rel="noreferrer"><code>StatefulSet</code></a> instead. Read on if this is for you:</p>
<p>My itch was to have a <code>PersistentVolume</code> that got re-used over and over by the container in a persistent way; the way that is the default behavior when using <code>docker</code> and <code>docker-compose</code> volumes. So that a new <code>PersistentVolume</code> only gets created once:</p>
<pre><code># Create a new PersistentVolume the very first time
kubectl apply  -f my.yaml 

# This leaves the &quot;volume&quot; - the PersistentVolume - alone
kubectl delete -f my.yaml

# Second and subsequent times re-use the same PersistentVolume
kubectl apply  -f my.yaml 
</code></pre>
<p>And I thought the way to do that was to declare a <code>PersistentVolumeClaim</code> with <code>reclaimPolicy: Retain</code> and then reference that in my deployment. But even when i got <code>reclaimPolicy: Retain</code> working, a brand new <code>PersistentVolume</code> still got created on every <code>kubectl apply</code>. <code>reclaimPolicy: Retain</code> just ensured that the old ones didn't get deleted.</p>
<p>But no. The way to achieve this use-case is with a <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/" rel="noreferrer"><code>StatefulSet</code></a>. It is way simpler, and then it behaves like I'm used to with docker and docker-compose.</p>
