3

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

I have used kubectl create -f pv.yaml

pv.yaml (with edits based on @whites11's answer):

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

I then create an example mongo replica set.

When I look at my k8s dashboard I see the error:

PersistentVolumeClaim is not bound: "mongo-persistent-storage-mongo-0" (repeated 2 times)

enter image description here

In the persistent volume tab I see the volume which looks ok:

enter image description here

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

Edit #2

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

enter image description here

Edit #3

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 - was auto-parsed out somewhere?

enter image description here

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

1 Answers1

5

You need to manually bind your PV to your PVC, by adding the appropriate claimRef section to the PV spec.

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

claimRef:
  name: mongo-persisted-storag
  namespace: <your PVC namespace>

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

volumeName: "<your volume name>"

Here an explanation on how this process works: https://docs.openshift.org/latest/dev_guide/persistent_volumes.html#persistent-volumes-volumes-and-claim-prebinding

whites11
  • 12,008
  • 3
  • 36
  • 53
  • thank you, I'm assuming if I'm not using a namespace both PV and services will all be on the default one? – Philip Kirkbride May 05 '18 at 13:44
  • PV is not namespaced, service will be on default if you don't specify it – whites11 May 05 '18 at 13:45
  • Sorry I'm still having trouble figuring this out. I updated my pv.yaml in my question based on your answer. Does it look right? I'm still getting the same results. – Philip Kirkbride May 05 '18 at 13:53
  • Is the PVC still unclaimed? – whites11 May 05 '18 at 14:01
  • Yes PVC shows as `pending` on one page and still this error on the StatefulSet `PersistentVolumeClaim is not bound: "mongo-persistent-storage-mongo-0" (repeated 2 times)` – Philip Kirkbride May 05 '18 at 14:03
  • Yeah sorry, try also adding volumeName in your PVC (answer updated) – whites11 May 06 '18 at 08:38
  • no problem it is hard to diagnose without the system in front of you. I added another edit to my question. – Philip Kirkbride May 06 '18 at 12:02
  • I don't know why but there seemed to be a problem with having `-` in the name of my volume. I did the same thing but with `pvvolume` instead of `pv-volume` and I was able to get past the error. I have a new error now but it is out of scope for the question. Thank you. – Philip Kirkbride May 06 '18 at 19:20