...
In this example will walk through creating a NFS server instanceServer instance, that exports storage that is backed by the default StorageClass (SC) for the environment you happen to be running in. In some environments, this could be a hostPath, in others it could be a cloud provider virtual disk. Either way, this example requires a default SC to exist.
...
| Code Block |
|---|
| language | yml |
|---|
| title | Default PV |
|---|
| collapse | true |
|---|
|
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv
labels:
type: local
spec:
storageClassName: local-storage # Same as the name of the default SC created
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/mnt/data" # The "data" folder, if it does not exist, will be created automatically on the node where the NFS serverServer pod is up and running. |
Create and Initialize NFS Server
Now that the operator is running, we can set up an instance of a NFS serverServer, creating an instance of the nfsservers.nfs.rook.io resource. The various fields and options of the NFS server Server resource can be used to configure the server and its volumes to export. With the nfs.yaml fileyaml file, now create the NFS server Server as shown
| Code Block |
|---|
| language | bash |
|---|
| title | NFS server |
|---|
| collapse | true |
|---|
|
$ kubectl create -f nfs.yaml
persistentvolumeclaim/nfs-default-claim created
nfsserver.nfs.rook.io/rook-nfs created |
We can verify that a Kubernetes object has been created, that represents our new NFS server Server and its export with the command
...
Verify, afterwards, that the NFS server Server pod is up and running. If the NFS server Server pod is in the Running state, then we have successfully created an exported NFS share, that clients can start to access over the network.
| Code Block |
|---|
| language | bash |
|---|
| title | Verify NFS server pod |
|---|
| collapse | true |
|---|
|
$ kubectl get pod -l app=rook-nfs -n rook-nfs
NAME READY STATUS RESTARTS AGE
rook-nfs-0 2/2 Running 0 43m |
Accessing the Export
Since Rook version v1.0, Rook supports dynamic provisioning of NFS. This example will be showing how dynamic provisioning feature can be used for NFS. Once the NFS Operator and an instance of NFS Server is deployed, a SC similar to sc.yaml has to be created to dynamically provisioning volumes
| Code Block |
|---|
| language | bash |
|---|
| title | sc.yaml |
|---|
| collapse | true |
|---|
|
$ k create -f sc.yaml
storageclass.storage.k8s.io/rook-nfs-share1 created |
| Info |
|---|
| title | Parameters necessary for the SC |
|---|
|
The SC need to have the following 3 parameters passed: exportName: it tells the provisioner which export to use for provisioning the volumes;nfsServerName: name of the NFS Server instance;nfsServerNamespace: namespace where the NFS Server instance is running.
|
Once you have created the SC above, you can create a PVC that references it. The PVC will automatically (dynamically) create the respective PV.
| Code Block |
|---|
| language | bash |
|---|
| title | pvc.yaml |
|---|
| collapse | true |
|---|
|
$ k create -f pvc.yaml
persistentvolumeclaim/rook-nfs-pv-claim created |