diff --git a/examples/kubernetes/nfs-provisioner/README.md b/examples/kubernetes/nfs-provisioner/README.md index bb877a0a5..1101308fd 100644 --- a/examples/kubernetes/nfs-provisioner/README.md +++ b/examples/kubernetes/nfs-provisioner/README.md @@ -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`. +- 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 get po nfs-server-pod +``` -To obtain a public IP for the service, run the following command instead +- 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/nfs-server-lb.yaml +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 +``` + diff --git a/examples/kubernetes/nfs-provisioner/app.yaml b/examples/kubernetes/nfs-provisioner/app.yaml new file mode 100644 index 000000000..0334efaf3 --- /dev/null +++ b/examples/kubernetes/nfs-provisioner/app.yaml @@ -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 \ No newline at end of file diff --git a/examples/kubernetes/nfs-provisioner/nfs-server-lb.yaml b/examples/kubernetes/nfs-provisioner/nfs-server-lb.yaml deleted file mode 100644 index 9bc968c16..000000000 --- a/examples/kubernetes/nfs-provisioner/nfs-server-lb.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/examples/kubernetes/nfs-provisioner/nfs-server.yaml b/examples/kubernetes/nfs-provisioner/nfs-server.yaml index e9c89e0dd..25d835050 100644 --- a/examples/kubernetes/nfs-provisioner/nfs-server.yaml +++ b/examples/kubernetes/nfs-provisioner/nfs-server.yaml @@ -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 \ No newline at end of file + 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: {} +--- \ No newline at end of file diff --git a/examples/kubernetes/nfs-provisioner/pv-nfs-csi.yaml b/examples/kubernetes/nfs-provisioner/pv-nfs-csi.yaml deleted file mode 100644 index e3c0261db..000000000 --- a/examples/kubernetes/nfs-provisioner/pv-nfs-csi.yaml +++ /dev/null @@ -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 \ No newline at end of file