Versions Compared

Key

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

Table of Contents

...

External Server Example

The usual patterns should work here:

...

  volumes:
  - name: nfs
    nfs:
      server: <NFS_SERVER_IP>
      path: /

...

Dynamic Volumes with the NFS Client Provisioner

For an easy way to get up and running serving shared volumes on Kubernetes from an existing NFS server, check out the nfs-client provisioner.

Provisioners like this one allow you to use Kubernetes to manage the lifecycle of your Kubernetes volumes and their data using PVCs, or PersistentVolumeClaims.

The basic workflow is as follows:

  1. User creates a PVC resource in Kubernetes with an attached StorageClass (if none is specified, the default will be used based on your cloud type - this blog post lists the default storage classes for each cloud provider)
  2. Kubernetes uses the StorageClass to determine how/whether a PV (PersistentVolume) should be created based on the claim parameters (e.g. for NFS, this effectively does a mkdir)
  3. If no existing static PV matches the parameters in the PVC, a new one should be dynamically created
  4. The PV can then be mounted into client pods by specifying the PVC name as a volume

For more details, see https://kubernetes.io/docs/concepts/storage/persistent-volumes/#dynamic

In-Cluster Server Example

Following this example, I was able to easily get an NFS server pod running within a Kubernetes 1.9 cluster.

...

Code Block
languagebash
# Create some duplicate pods consuming the same NFS mount
ubuntu@mltf-master:~/kubernetes-nfs-server$ kubectl create -f web-pod2.yaml -f web-pod3.yaml 
pod "web2" created
pod "web3" created


# Wait for containers to start
ubuntu@mltf-master:~/kubernetes-nfs-server$ kubectl get pods -o wide
NAME               READY     STATUS              RESTARTS   AGE       IP           NODE
nfs-server-wc8h6   1/1       Running             0          49m       10.244.1.4   mltf-storage0
web                1/1       Running             0          39m       10.244.3.2   mltf-storage1
web2               0/1       ContainerCreating   0          8s        <none>       mltf-storage0
web3               0/1       ContainerCreating   0          8s        <none>       mltf-worker0


# Verify that the file created inside of our original web pod (running on "storage1") also shows up here
ubuntu@mltf-master:~/kubernetes-nfs-server$ kubectl exec -it web2 -- cat /usr/share/nginx/html/pod-write
asdf 1234 Hello, World!
ubuntu@mltf-master:~/kubernetes-nfs-server$ kubectl exec -it web3 -- cat /usr/share/nginx/html/pod-write
asdf 1234 Hello, World!

Dynamic Volumes using the NFS Provisioner

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

...

Congratulations! Wasn't that easy?

Testing it Out

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

...