How do I use PV and PVC for *reliable* persistent volumes?

10/8/2018

I followed the instructions in this post: how to bound a Persistent volume claim with a gcePersistentDisk?

And when I applied that, my PVC did not bind to the PV, instead I got this error in the event list:

14s         17s          2         test-pvc.155b8df6bac15b5b   PersistentVolumeClaim               Warning   ProvisioningFailed   persistentvolume-controller   Failed to provision volume with StorageClass "standard": claim.Spec.Selector is not supported for dynamic provisioning on GCE

I found a github posting that suggested something that would fix this:

https://github.com/coreos/prometheus-operator/issues/323#issuecomment-299016953

But unfortunately that made no difference.

Is there a soup-to-nuts doc somewhere telling us exactly how to use PV and PVC to create truly persistent volumes? Specifically where you can shut down the pv and pvc and restore them later, and get all your content back? Because as it seems right now, if you lose your PVC for whatever reason, you lose connection to your volume and there is no way to get it back again.

-- Colin Fox
google-cloud-platform
kubernetes
persistent-volume-claims
persistent-volumes

1 Answer

10/9/2018

The default StorageClass is not compatible with a gcePesistentDisk. Something like this would work:

$ cat <<EOF | kubectl create -f -
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: slow
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-standard
  replication-type: none
EOF

then on your PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
  labels:
    app: test
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: "slow" <== specify the storageClass
  resources:
    requests:
      storage: 2Gi
  selector:
    matchLabels:
      app: test

You can also set "slow" as the default storageClass in which case you wouldn't have to specify it on your PVC:

$ kubectl patch storageclass slow -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
-- Rico
Source: StackOverflow