Kubernetes 1.6 Auto Provisioning With NFS

4/12/2017

The newly stable Auto-Provisioning features of Kubernetes seemingly eliminates the need to define PersistentVolumes and, based on its StorageClass, result in a PersistentVolumeClaim just having its needs met.

This all seems a bit simpler but I'm at a bit of a loss what to do when it comes to updating my manifests for the canonical NFS example

Before 1.6, the following PVC and PV would be bound together and several other services could use the ReadWriteMany PVC nfs-pvc without problem

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
  namespace: staging
spec:
  capacity:
    storage: 1Mi
  accessModes: [ "ReadWriteMany" ]
  persistentVolumeReclaimPolicy: Delete
  nfs:
    # FIXME: use the right IP
    server: 10.7.252.23
    path: "/exports"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs-pvc
  namespace: staging
spec:
  accessModes: [ "ReadWriteMany" ]
  resources:
    requests:
      storage: 1Mi

(Please note i have only now added the persistentVolumeReclaimPolicy but does not affect things)

However, in 1.6, running this manifest results in an additional PV pv/pvc-75f9e8d1-1f69-11e7-b065-42010a84002d. Presumably this is due to the auto-provisioning. Unfortunately, this isn't NFS.

Matthews-iMac:gke matt$ k get pv,pvc
NAME                                          CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM                            STORAGECLASS   REASON    AGE
pv/nfs                                        1Mi        RWX           Delete          Available                                                             18m
pv/postgres-volume                            100Gi      RWO           Retain          Bound       default/postgres-storage-claim   fast                     16h
pv/pvc-630748eb-1f69-11e7-b065-42010a84002d   100Gi      RWO           Delete          Bound       staging/nfs-server-pvc           standard                 18m
pv/pvc-75f9e8d1-1f69-11e7-b065-42010a84002d   1Gi        RWX           Delete          Bound       staging/nfs-pvc                  standard                 18m

NAME                 STATUS    VOLUME                                     CAPACITY   ACCESSMODES   STORAGECLASS   AGE
pvc/nfs-pvc          Bound     pvc-75f9e8d1-1f69-11e7-b065-42010a84002d   1Gi        RWX           standard       18m
pvc/nfs-server-pvc   Bound     pvc-630748eb-1f69-11e7-b065-42010a84002d   100Gi      RWO           standard       18m

I think i may be missing something with regard to selector or something? I tried adding selector -> matchLabel but this isn't supported by the GCE provisioner apparently. Thanks for your help

-- elmpp
google-compute-engine
kubernetes

1 Answer

4/12/2017

So, I think i got to the bottom of this. The documentation

around "Class" mentions that when the "admission plugin" is enabled (as it is on GKE), it is necessary to specify within the PVC a storageClass: "". This effectively means the PVC will only be considered for PVs that have no storageClass.

This is my updated manifest:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
  namespace: staging
spec:
  capacity:
    storage: 1Mi
  accessModes: [ "ReadWriteMany" ]
  persistentVolumeReclaimPolicy: Delete
  nfs:
    # FIXME: use the right IP
    server: 10.7.252.23
    path: "/exports"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs-pvc
  namespace: staging
spec:
  accessModes: [ "ReadWriteMany" ]
  resources:
    requests:
      storage: 1Mi
  storageClassName: "" # setting this to empty means this pvc can only be bound to pv with no class (i.e. not dynamically provisioned!)

And my bound instances:

Matthews-iMac:gke matt$ k get pv,pvc
NAME                                          CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS     CLAIM                            STORAGECLASS   REASON    AGE
pv/nfs                                        1Mi        RWX           Delete          Bound      staging/nfs-pvc                                           5m
pv/postgres-volume                            100Gi      RWO           Retain          Bound      default/postgres-storage-claim   fast                     18h
pv/pvc-1d61980f-1f67-11e7-b065-42010a84002d   1Gi        RWX           Delete          Released   staging/nfs-pvc                  standard                 2h
pv/pvc-630748eb-1f69-11e7-b065-42010a84002d   100Gi      RWO           Delete          Bound      staging/nfs-server-pvc           standard                 1h

NAME                 STATUS    VOLUME                                     CAPACITY   ACCESSMODES   STORAGECLASS   AGE
pvc/nfs-pvc          Bound     nfs                                        1Mi        RWX                          5m
pvc/nfs-server-pvc   Bound     pvc-630748eb-1f69-11e7-b065-42010a84002d   100Gi      RWO           standard       1h
Matthews-iMac:gke matt$
-- elmpp
Source: StackOverflow