Add working NFS provisioner example

Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
This commit is contained in:
Mayank Shah 2020-10-11 19:58:53 +05:30
parent acfbbd9c4b
commit cf2d67560c
5 changed files with 108 additions and 104 deletions

View File

@ -1,18 +1,28 @@
# Set up a NFS Server on a Kubernetes cluster
> Note: This example is for development perspective only. Because the NFS server is sticky to the node it is scheduled on, data shall be lost if the pod is rescheduled on another node.
> Note: This example is for development only. Because the NFS server is sticky to the node it is scheduled on, data shall be lost if the pod is rescheduled on another node.
To create a NFS provisioner on your Kubernetes cluster, run the following command
- To create a NFS provisioner on your Kubernetes cluster, run the following command
```bash
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/examples/kubernetes/nfs-provisioner/nfs-server.yaml
```
After deploying, a new service `nfs-server` is created. The file share path is accessible at `nfs-server.default.svc.cluster.local/nfsshare`.
To obtain a public IP for the service, run the following command instead
- After deploying, a new service `nfs-service` is created. The file share path is accessible at `10.0.171.239`. Verify if the NFS Server pod is running
```bash
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/examples/kubernetes/nfs-provisioner/nfs-server-lb.yaml
$ kubectl get po nfs-server-pod
```
- To check if the server is working, we can statically create a `PersistentVolume` and a `PersistentVolumeClaim`, and mount it onto a sample pod:
```bash
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/examples/kubernetes/nfs-provisioner/app.yaml
```
Verify if the newly create deployment is Running:
```bash
$ kubectl get deploy nfs-busybox
```

View File

@ -0,0 +1,61 @@
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nfs
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /
server: 10.0.171.239
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nfs
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
volumeName: pv-nfs
storageClassName: ""
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-busybox
spec:
replicas: 1
selector:
matchLabels:
name: nfs-busybox
template:
metadata:
name: nfs-busybox
labels:
name: nfs-busybox
spec:
containers:
- image: busybox
command:
- sh
- -c
- 'while true; do date > /mnt/index.html; hostname >> /mnt/index.html; sleep $(($RANDOM % 5 + 5)); done'
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
- name: nfs
mountPath: "/mnt"
volumes:
- name: nfs
persistentVolumeClaim:
claimName: nfs

View File

@ -1,43 +0,0 @@
---
kind: Service
apiVersion: v1
metadata:
name: nfs-server
labels:
app: nfs-server
spec:
type: LoadBalancer
selector:
app: nfs-server
ports:
- port: 2049
name: nfs-server
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: nfs-server
spec:
replicas: 1
selector:
matchLabels:
app: nfs-server
template:
metadata:
name: nfs-server
labels:
app: nfs-server
spec:
containers:
- name: nfs-server
image: gcr.io/kubernetes-e2e-test-images/volume/nfs:1.0
ports:
- containerPort: 2049
volumeMounts:
- mountPath: /nfsshare
name: data-volume
volumes:
- name: data-volume
hostPath:
path: /exports
type: DirectoryOrCreate

View File

@ -1,43 +1,39 @@
---
kind: Service
apiVersion: v1
metadata:
name: nfs-server
labels:
app: nfs-server
name: nfs-service
spec:
type: ClusterIP # use "LoadBalancer" to get a public ip
clusterIP: 10.0.171.239
selector:
app: nfs-server
role: nfs
ports:
- port: 2049
name: nfs-server
- name: tcp-2049
port: 2049
protocol: TCP
- name: udp-111
port: 111
protocol: UDP
---
kind: Deployment
apiVersion: apps/v1
kind: Pod
apiVersion: v1
metadata:
name: nfs-server
name: nfs-server-pod
labels:
role: nfs
spec:
replicas: 1
selector:
matchLabels:
app: nfs-server
template:
metadata:
name: nfs-server
labels:
app: nfs-server
spec:
containers:
- name: nfs-server
image: gcr.io/kubernetes-e2e-test-images/volume/nfs:1.0
ports:
- containerPort: 2049
volumeMounts:
- mountPath: /nfsshare
name: data-volume
volumes:
- name: data-volume
hostPath:
path: /exports
type: DirectoryOrCreate
containers:
- name: nfs-server-container
image: itsthenetwork/nfs-server-alpine:latest
env:
- name: SHARED_DIRECTORY
value: "/exports"
volumeMounts:
- mountPath: /exports
name: nfs-vol
securityContext:
privileged: true
volumes:
- name: nfs-vol
emptyDir: {}
---

View File

@ -1,20 +0,0 @@
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nfs
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
mountOptions:
- vers=3.0
csi:
driver: nfs.csi.k8s.io
readOnly: false
volumeHandle: unique-volumeid # make sure it's a unique id in the cluster
volumeAttributes:
server: nfs-server.default.svc.cluster.local
share: /nfsshare