Yudi
Yudi

Reputation: 921

Kubernetes : Dynamic Persistent Volume provisioning using NFS

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,

nfs-storage-class.yaml

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: <nfs-server-ip> 

nfs-pv-claim.yaml

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

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

Upvotes: 15

Views: 20770

Answers (6)

c-x-berger
c-x-berger

Reputation: 1051

As of May 2024, here's how things look for NFS persistence on Kubernetes:

You can

  • Put an NFS volume on a Pod directly:
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
  • Manually create a Persistent Volume backed by NFS, and mount it with a Persistent Volume Claim (PV spec shown below):
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
  • Use the NFS Subdir External Provisioner. This lets you make a StorageClass to fulfill PersistentVolumeClaims from an existing NFS server. Setting up the provisioner requires a few resources - the easiest way to install it is probably the Helm chart.
  • Evidently, CSI is the future, and there is an NFS CSI driver.
  • There's always various things from the community. In researching this problem, I stumbled on a provisioner written by someone on GitHub, for example. Whether such provisioners perform well, are secure, or work at all is beyond me, but they do exist.

Upvotes: 8

Regis Lima
Regis Lima

Reputation: 11

If you are using AWS, I believe you can use this image to create a NFS server:

https://hub.docker.com/r/alphayax/docker-volume-nfs

Upvotes: 0

Oswin Noetzelmann
Oswin Noetzelmann

Reputation: 9555

The purpose of StorageClass is to create storage, e.g. from cloud providers (or "Provisioner" as they call it in the kubernetes docs). In case of NFS you only want to get access to existing storage and there is no creation involved. Thus you don't need a StorageClass. Please refer to this blog.

Upvotes: 1

Hanno Kolvenbach
Hanno Kolvenbach

Reputation: 319

I also tried to enable the NFS provisioner on my kubernetes cluster and at first it didn't work, because the quickstart guide does not mention that you need to apply the rbac.yaml as well (I opened a PR to fix this).

The nfs provisioner works fine for me if I follow these steps on my cluster: https://github.com/kubernetes-incubator/external-storage/tree/master/nfs#quickstart

$ kubectl create -f deploy/kubernetes/deployment.yaml
$ kubectl create -f deploy/kubernetes/rbac.yaml
$ kubectl create -f deploy/kubernetes/class.yaml

Then you should be able to create PVCs like this:

$ kubectl create -f deploy/kubernetes/claim.yaml

You might want to change the folders used for the volume mounts in deployment.yaml to match it with your cluster.

Upvotes: 2

karthik101
karthik101

Reputation: 1719

Dynamic storage provisioning using NFS doesn't work, better use glusterfs. There's a good tutorial with fixed to common problems while setting up. http://blog.lwolf.org/post/how-i-deployed-glusterfs-cluster-to-kubernetes/

Upvotes: 2

xeor
xeor

Reputation: 5455

I'm looking into doing the same thing. I found https://github.com/kubernetes-incubator/external-storage/tree/master/nfs, which I think you based your provisioner on?

I think an nfs provider would need to create a unique directory under the path defined. I'm not really sure how this could be done.

Maybe this is better of as an github issue on the kubernetes repo.

Upvotes: 2

Related Questions