<p><strong>Description</strong>:
Unable to bind a new PVC to an existing PV that already contains data from previous run (and was dynamically created using gluster storage class).</p>

<ul>
<li>Installed a helm release which created PVC and  dynamically generated PV from GlusterStorage class.</li>
<li>However due to some reason, we need to bring down the release (<code>helm del</code>) and re-install it (<code>helm install</code>). However, want to use the existing PV instead of creating a new one.</li>
</ul>

<p>I tried a few things:
- Following the instruction here: <a href="https://github.com/kubernetes/kubernetes/issues/48609" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/48609</a>. However, that did not work for GlusterFS storage solution since after I tried the needed steps, it complained:</p>

<pre><code>  Type     Reason            Age                From                              Message
  ----     ------            ----               ----                              -------
  Warning  FailedScheduling  &lt;unknown&gt;          default-scheduler                 error while running "VolumeBinding" filter plugin for pod "opensync-wifi-controller-opensync-mqtt-broker-fbbd69676-bmqqm": pod has unbound immediate PersistentVolumeClaims
  Warning  FailedScheduling  &lt;unknown&gt;          default-scheduler                 error while running "VolumeBinding" filter plugin for pod "opensync-wifi-controller-opensync-mqtt-broker-fbbd69676-bmqqm": pod has unbound immediate PersistentVolumeClaims
  Normal   Scheduled         &lt;unknown&gt;          default-scheduler                 Successfully assigned connectus/opensync-wifi-controller-opensync-mqtt-broker-fbbd69676-bmqqm to rahulk8node1-virtualbox
  Warning  FailedMount       31s (x7 over 62s)  kubelet, rahulk8node1-virtualbox  MountVolume.NewMounter initialization failed for volume "pvc-dc52b290-ae86-4cb3-aad0-f2c806a23114" : endpoints "glusterfs-dynamic-dc52b290-ae86-4cb3-aad0-f2c806a23114" not found
  Warning  FailedMount       30s (x7 over 62s)  kubelet, rahulk8node1-virtualbox  MountVolume.NewMounter initialization failed for volume "pvc-735baedf-323b-47bc-9383-952e6bc5ce3e" : endpoints "glusterfs-dynamic-735baedf-323b-47bc-9383-952e6bc5ce3e" not found
</code></pre>

<p>Apparently besides the PV, we would also need to persist gluster-dynamic-endpoints and glusterfs-dynamic-service. However, these are created in the pod namespace and since the <em>namespace is removed</em> as part of <code>helm del</code>, it also deletes these endpoints and svc. </p>

<p>I looked around other pages related to GlusterFS endpoint missing: <a href="https://github.com/openshift/origin/issues/6331" rel="nofollow noreferrer">https://github.com/openshift/origin/issues/6331</a> but that does not applies to the current version of Storage class. When I added <code>endpoint: "heketi-storage-endpoints"</code> to the Storage class parameters, I got the following error when creating the PVC:</p>

<pre><code>Failed to provision volume with StorageClass "glusterfs-storage": invalid option "endpoint" for volume plugin kubernetes.io/glusterfs
</code></pre>

<p>This option was removed in 2016 - see <a href="https://github.com/gluster/gluster-kubernetes/issues/87" rel="nofollow noreferrer">https://github.com/gluster/gluster-kubernetes/issues/87</a>. </p>

<p>Is there anyway to use existing PV from a new PVC? </p>

Rahul Sharma
<p>I would like to suggest a different approach.</p>
<p>You can use this annotation on the PVC, it will skip deleting the resource on delete.</p>
<pre><code>helm.sh/resource-policy: &quot;keep&quot;
</code></pre>
<p><a href="https://github.com/helm/charts/blob/master/stable/bitcoind/templates/pvc.yaml" rel="nofollow noreferrer">Here</a> is an example:</p>
<pre class="lang-yaml prettyprint-override"><code>{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: {{ template &quot;bitcoind.fullname&quot; . }}
  annotations:
    &quot;helm.sh/resource-policy&quot;: keep
  labels:
    app: {{ template &quot;bitcoind.name&quot; . }}
    chart: &quot;{{ .Chart.Name }}-{{ .Chart.Version }}&quot;
    release: &quot;{{ .Release.Name }}&quot;
    heritage: &quot;{{ .Release.Service }}&quot;
spec:
  accessModes:
    - {{ .Values.persistence.accessMode | quote }}
  resources:
    requests:
      storage: {{ .Values.persistence.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq &quot;-&quot; .Values.persistence.storageClass) }}
  storageClassName: &quot;&quot;
{{- else }}
  storageClassName: &quot;{{ .Values.persistence.storageClass }}&quot;
{{- end }}
{{- end }}
{{- end }} 
</code></pre>
<p>You can also use parameters as seen <a href="https://github.com/helm/charts/tree/master/stable/hoard" rel="nofollow noreferrer">here</a>, where they implemented an option to flag (which is either true or false) while you install your helm chart.</p>
<pre><code>persistence.annotations.&quot;helm.sh/resource-policy&quot;
</code></pre>
<p>You can also include a configurable parameters to set the name of the pvc you want to reuse as seen <a href="https://github.com/helm/charts/tree/master/stable/mysql" rel="nofollow noreferrer">here</a>.</p>
<p>In this example you can set <code>persistence.existingClaim=mysql-pvc</code> during your chart install.</p>
<p>So mixing everything you can have something that should look like this when you run your helm install:</p>
<pre><code>helm install --namespace myapp --set existingClaim=mysql-pvc stable/myapp
</code></pre>
