<p>Given the following PVC and PV:</p>

<ul>
<li>PVC:</li>
</ul>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: packages-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  volumeName: packages-volume
</code></pre>

<ul>
<li>PV:</li>
</ul>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: packages-volume
  namespace: test
spec:
  claimRef:
    name: packages-pvc
    namespace: test
  accessModes:
    - ReadWriteMany
  nfs:
    path: {{NFS_PATH}}
    server: {{NFS_SERVER}}
  capacity:
    storage: 1Gi
  persistentVolumeReclaimPolicy: Retain
</code></pre>

<p>if I create the PV, then the PVC, they bind together. However if I delete the PVC then re-create it, they do not bind (pvc pending). Why?</p>

<p>Note that after deleting <code>PVC</code>, <code>PV</code> remains in <code>Released</code> status:</p>

<pre><code>$ kubectl get pv packages-volume
NAME              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM                  STORAGECLASS   REASON   AGE
packages-volume   1007Gi     RWX            Retain           Released   default/packages-pvc                           10m
</code></pre>

<p>It should have status <code>Available</code> so it can be reused by another <code>PersistentVolumeClaim</code> instance.</p>

<p><strong>Why it isn't <code>Available</code> ?</strong></p>

<p>If you display current <code>yaml</code> definition of the <code>PV</code>, which you can easily do by executing:</p>

<pre><code>kubectl get pv packages-volume -o yaml
</code></pre>

<p>you may notice that in <code>claimRef</code> section it contains the <code>uid</code> of the recently deleted <code>PersistentVolumeClaim</code>:</p>

<pre><code>  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: packages-pvc
    namespace: default
    resourceVersion: "10218121"
    uid: 1aede3e6-eaa1-11e9-a594-42010a9c0005
</code></pre>

<p>You can easily verify it by issuing:</p>

<pre><code>kubectl get pvc packages-pvc -o yaml | grep uid
</code></pre>

<p>just before you delete your <code>PVC</code> and compare it with what <code>PV</code> definition contains. You'll see that this is exactly the same <code>uid</code> that is still referred by your <code>PV</code> after <code>PVC</code> is deleted. This remaining reference is the actual reason that <code>PV</code> remains in <code>Released</code> status.</p>

<p><strong>Why newly created <code>PVC</code> remains in a <code>Pending</code> state ?</strong></p>

<p>Although your newly created <code>PVC</code> may seem to you exactly the same <code>PVC</code> that you've just deleted as you're creating it using the very same <code>yaml</code> file, from the perspective of <code>Kubernetes</code> it's a completely new instance of <code>PersistentVolumeClaim</code> object which has completely different <code>uid</code>. This is the reason why it remains in <code>Pending</code> status and is unable to bind to the <code>PV</code>.</p>

<p><strong>Solution:</strong></p>

<p>To make the <code>PV</code> <code>Available</code> again you just need to remove the mentioned <code>uid</code> reference e.g. by issuing:</p>

<pre><code>kubectl patch pv packages-volume --type json -p '[{"op": "remove", "path": "/spec/claimRef/uid"}]'
</code></pre>

<p>or alternatively by removing the whole <code>claimRef</code> section which can be done as follows:</p>

<pre><code>kubectl patch pv packages-volume --type json -p '[{"op": "remove", "path": "/spec/claimRef"}]'
</code></pre>
