Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Dynamic Volumes using the NFS Provisioner

Coming soon!

See https://github.com/kubernetes-incubator/external-storage/tree/master/nfs

In a slightly more complex example, we can actually have Kubernetes provision volumes dynamically for us from an NFS export.

  1. Clone the repo above
  2. Locate the nfs/deploy/kubernetes subfolder
  3. Edit deployment.yaml (e.g. change nodeSelector, change mount path/config)
  4. kubectl create -f auth/serviceaccount.yaml -f auth/clusterrole.yaml -f auth/clusterrolebinding.yaml
  5. kubectl create -f class.yaml -f deployment.yaml

Congratulations! Wasn't that easy?

Testing it Out

A simple test case for consuming a dynamic PVC can be found below:

  1. kubectl create -f claim.yaml
  2. kubectl create -f write_pod.yaml

Expected output:

Code Block
languagebash
ubuntu@mltf-master:~/external-storage/nfs/deploy/kubernetes$ kubectl get pvc,pv
NAME                        STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/nfs   Bound     pvc-253140dc-6dc2-11e8-9b58-fa163eace583   1Mi        RWX            example-nfs    15m
 
NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM         STORAGECLASS   REASON    AGE
persistentvolume/pvc-253140dc-6dc2-11e8-9b58-fa163eace583   1Mi        RWX            Delete           Bound     default/nfs   example-nfs              15m
 
# Look up the UID of our PVC (we will need this to find it on disk later)
ubuntu@mltf-master:~/external-storage/nfs/deploy/kubernetes$ kubectl get pvc -o yaml
apiVersion: v1
items:
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    annotations:
      control-plane.alpha.kubernetes.io/leader: '{"holderIdentity":"c9839a10-6dc1-11e8-b790-0a580af40112","leaseDurationSeconds":15,"acquireTime":"2018-06-11T21:55:25Z","renewTime":"2018-06-11T21:55:27Z","leaderTransitions":0}'
    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...
      volume.beta.kubernetes.io/storage-class: example-nfs
      volume.beta.kubernetes.io/storage-provisioner: example.com/nfs
    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...
    uid: 253140dc-6dc2-11e8-9b58-fa163eace583
  spec:
    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...
      requests:
        storage: 1Mi
    volumeName: pvc-253140dc-6dc2-11e8-9b58-fa163eace583
  status:
    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...
 
# Wait for the write-pod to finish executing
ubuntu@mltf-master:~/external-storage/nfs/deploy/kubernetes$ kubectl get pods
NAME                               READY     STATUS      RESTARTS   AGE            NODE
mongo-k2pqv                        1/1       Running     0          1h   mltf-worker0
ndslabs-apiserver-pd62v            2/2       Running     0          1h   mltf-storage1
ndslabs-etcd-ppsdv                 1/1       Running     0          23m   mltf-worker0
ndslabs-webui-qx4fb                1/1       Running     0          1h   mltf-storage1
nfs-provisioner-7f78fcc699-vjr8d   1/1       Running     0          6m   mltf-storage0
nfs-server-wc8h6                   1/1       Running     0          5h    mltf-storage0
web                                1/1       Running     0          2h    mltf-storage0
web2                               1/1       Running     0          4h    mltf-storage0
web3                               1/1       Running     0          4h    mltf-worker0
write-pod                          0/1       Completed   0          2m    mltf-storage1    <-------
 
# SSH into "storage0" (this is where the nfs-provisioner is currently running)
ubuntu@mltf-master:~/external-storage/nfs/deploy/kubernetes$ ssh 192.168.0.3
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-127-generic x86_64)
 
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
 
  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud
 
14 packages can be updated.
7 updates are security updates.
 
 
Last login: Mon Jun 11 21:55:53 2018 from 192.168.0.6
 
# Locate the subdirectory of the nfs-provisioner on our OpenStack volume for shared storage
ubuntu@mltf-storage0:~$ ls -al /data
total 32
drwxr-xr-x  5 root root  4096 Jun 11 21:51 .
drwxr-xr-x 26 root root  4096 Jun 11 21:19 ..
drwx------  2 root root 16384 Jun  8 22:46 lost+found
drwxr-xr-x  4 root root  4096 Jun 11 20:52 nfs
drwxr-xr-x  3 root root  4096 Jun 11 21:55 nfs-provisioner
 
# Locate the subdirectory of our specific PVC (NOTE: this will match the "volume name" and UID of the PVC we looked up earlier)
ubuntu@mltf-storage0:~$ ls -al /data/nfs-provisioner/
total 36
drwxr-xr-x 3 root root  4096 Jun 11 21:55 .
drwxr-xr-x 5 root root  4096 Jun 11 21:51 ..
-rw-r--r-- 1 root root 14791 Jun 11 21:55 ganesha.log
-rw------- 1 root root    36 Jun 11 21:51 nfs-provisioner.identity
drwxrwsrwx 2 root root  4096 Jun 11 21:56 pvc-253140dc-6dc2-11e8-9b58-fa163eace583
-rw------- 1 root root   902 Jun 11 21:55 vfs.conf
 
# Verify the contents of the PVC
ubuntu@mltf-storage0:~$ ls -al /data/nfs-provisioner/pvc-253140dc-6dc2-11e8-9b58-fa163eace583/
total 8
drwxrwsrwx 2 root root 4096 Jun 11 21:56 .
drwxr-xr-x 3 root root 4096 Jun 11 21:55 ..
-rw-r--r-- 1 root root    0 Jun 11 21:56 SUCCESS     <------