<p>I have multi node kubernetes setup. I am trying to allocate a Persistent volume dynamically using storage classes with NFS volume plugin. 
I found storage classes examples for glusterfs, aws-ebs, etc.but, I didn't find any example for NFS.
If I create PV and PVC only then NFS works very well(Without storage class).
I tried to write storage class file for NFS, by referring other plugins. please refer it below,</p>

<p>nfs-storage-class.yaml</p>

<pre><code>kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  namespace: kube-system
  name: my-storage
  annotations:
    storageclass.beta.kubernetes.io/is-default-class: "true"
  labels:
    kubernetes.io/cluster-service: "true"

provisioner: kubernetes.io/nfs
parameters:
  path: /nfsfileshare
  server: &lt;nfs-server-ip&gt; 
</code></pre>

<p>nfs-pv-claim.yaml</p>

<pre><code>apiVersion: v1
metadata:
  name: demo-claim
  annotations:
    volume.beta.kubernetes.io/storage-class: my-storage
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
</code></pre>

<p>It didn't worked. So, my question is, Can we write a storage class for NFS? Does it support dynamic provisioing?</p>

<p>As of August 2020, here's how things look for NFS persistence on Kubernetes:</p>
<p>You can</p>
<ul>
<li>Put an NFS volume on a Pod directly:</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    nfs:
      path: /foo/bar
      server: wherever.dns
</code></pre>
<ul>
<li>Manually create a Persistent Volume backed by NFS, and mount it with a Persistent Volume Claim (PV spec shown below):</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
  - hard
  - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2
</code></pre>
<ul>
<li>Use the (now deprecated) <a href="https://github.com/kubernetes-retired/external-storage/tree/master/nfs" rel="nofollow noreferrer">NFS PV provisioner</a> from <code>external-storage</code>. This was last updated two years ago, and has been officially EOL'd, so good luck. With this route, you can make a Storage Class such as the one below to fulfill PVCs from your NFS server.
<ul>
<li><strong>Update:</strong> There is a new incarnation of this provisioner as <a href="https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner" rel="nofollow noreferrer"><code>kubernetes-sigs/nfs-subdir-external-provisioner</code>!</a> It seems to work in a similar way to the old <code>nfs-client</code> provisioner, but is much more up-to-date. Huzzah!</li>
</ul>
</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: example-nfs
provisioner: example.com/nfs
mountOptions:
- vers=4.1
</code></pre>
<ul>
<li>Evidently, CSI is the future, and <a href="https://github.com/kubernetes-csi/csi-driver-nfs" rel="nofollow noreferrer">there is a NFS CSI driver.</a> However, it doesn't support dynamic provisioning yet, so it's not really terribly useful.
<ul>
<li><strong>Update (December 2020):</strong> Dynamic provisioning is apparently in the works (on <code>master</code>, but not released) for the CSI driver.</li>
</ul>
</li>
<li>You might be able to replace <code>external-storage</code>'s NFS provisioner with something from the community, or something you write. In researching this problem, I stumbled on <a href="https://github.com/juliohm1978/kubernetes-nfs-volume-provisioner" rel="nofollow noreferrer">a provisioner written by someone on GitHub,</a> for example. Whether such provisioners perform well, are secure, or work at all is beyond me, but they do exist.</li>
</ul>
