<p>I'm in the process of converting a stack to k8s. The database requires persistent storage.</p>

<p>I have used <code>kubectl create -f pv.yaml</code></p>

<p><strong>pv.yaml <em>(with edits based on @whites11's answer)</em>:</strong></p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/nfs"
  claimRef:
    kind: PersistentVolumeClaim
    namespace: default
    name: mongo-persisted-storage
</code></pre>

<p>I then create an <a href="https://github.com/cvallance/mongo-k8s-sidecar/blob/master/example/StatefulSet/mongo-statefulset.yaml" rel="nofollow noreferrer">example mongo replica set</a>.</p>

<p>When I look at my k8s dashboard I see the error:</p>

<blockquote>
  <p>PersistentVolumeClaim is not bound: "mongo-persistent-storage-mongo-0"
  (repeated 2 times)</p>
</blockquote>

<p><a href="https://i.stack.imgur.com/5cs3a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5cs3a.png" alt="enter image description here"></a></p>

<p>In the persistent volume tab I see the volume which looks ok:</p>

<p><a href="https://i.stack.imgur.com/i8KU6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i8KU6.png" alt="enter image description here"></a></p>

<p>I'm having trouble figuring out the next step to make the volume claim happen successfully.</p>

<h3>Edit #2</h3>

<p>I went into the PVC page on the GUI and added a volume to the claim manually <em>(based on feedback from @whites11)</em>. I can see that the PVC has been updated with the volume but it is still pending.</p>

<p><a href="https://i.stack.imgur.com/MXnGL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MXnGL.png" alt="enter image description here"></a></p>

<h3>Edit #3</h3>

<p>Realizing that since making the change suggested by @whites11, the original error message in the pod has changed. It is now "persistentvolume "pvvolume" not found (repeated 2 times)", I think I just need to figure out where I wrote pvvolume, instead of pv-volume. (or it could be the <code>-</code> was auto-parsed out somewhere?</p>

<p><a href="https://i.stack.imgur.com/alBWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/alBWR.png" alt="enter image description here"></a></p>

Philip Kirkbride
<p>You need to manually bind your PV to your PVC, by adding the appropriate <code>claimRef</code> section to the PV spec.</p>

<p>In practice, edit your PV with the method you prefer, and add a section similar to this:</p>

<pre><code>claimRef:
  name: mongo-persisted-storag
  namespace: &lt;your PVC namespace&gt;
</code></pre>

<p>Than, you need to edit your PVC to bind the correct volume, by adding the following in its <code>spec</code> section:</p>

<pre><code>volumeName: "&lt;your volume name&gt;"
</code></pre>

<p>Here an explanation on how this process works: <a href="https://docs.openshift.org/latest/dev_guide/persistent_volumes.html#persistent-volumes-volumes-and-claim-prebinding" rel="nofollow noreferrer">https://docs.openshift.org/latest/dev_guide/persistent_volumes.html#persistent-volumes-volumes-and-claim-prebinding</a></p>
