preloader
  • Home
  • OpenShift NFS Storage Class

NFS Volumes for OpenShift Clusters

blog-thumb

You can use your existing NFS server for dynamic provisioning of Kubernetes Persistent Volumes.

NFS subdir external provisioner is an automatic provisioner that use your existing and already configured NFS server to support dynamic provisioning of Kubernetes Persistent Volumes via Persistent Volume Claims.

Persistent volumes are provisioned as ${namespace}-${pvcName}-${pvName}.

If you need a NFS Server, click here to learn how to deploy one.


NFS Subdir External Provisioner

The provisioner is responsible for providing an NFS client service that will give OpenShift access to shared volumes from an NFS Server.


Clone the repo and create the namespace
$ git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner.git
$ cd nfs-subdir-external-provisioner
$ oc create namespace openshift-nfs-storage
$ oc label namespace openshift-nfs-storage "openshift.io/cluster-monitoring=true"
$ oc project openshift-nfs-storage

Replace the namespace on the YAMLs
$ NAMESPACE=`oc project -q`
$ sed -i '' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/rbac.yaml
$ sed -i '' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/deployment.yaml

Security Context Constraints
$ oc create -f deploy/rbac.yaml
$ oc adm policy add-scc-to-user hostmount-anyuid system:serviceaccount:$NAMESPACE:nfs-client-provisioner

NFS Provisioner

The PROVISIONER_NAME should be "nfs".

Edit "deploy/deployment.yaml" and change:

From:

          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 10.10.10.60
            - name: NFS_PATH
              value: /ifs/kubernetes
      volumes:
        - name: nfs-client-root
          nfs:
            server: 10.10.10.60
            path: /ifs/kubernetes

To:

          env:
            - name: PROVISIONER_NAME
              value: nfs
            - name: NFS_SERVER
              value: YOUR_NFS_SERVER_IP_OR_FQDN
            - name: NFS_PATH
              value: /shares
      volumes:
        - name: nfs-client-root
          nfs:
            server: YOUR_NFS_SERVER_IP_OR_FQDN
            path: /shares
  • – Be sure to replace YOUR_NFS_SERVER_IP_OR_FQDN by you NFS server address.


Update the storage class
$ cat > deploy/class.yaml << EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
provisioner: slow
parameters:
  archiveOnDelete: "false"
EOF

Deploy NFS OCP Client
$ oc create -f deploy/class.yaml
$ oc create -f deploy/deployment.yaml

Security Context Constraints (again)
$ oc get deployment -n openshift-nfs-storage -o yaml | oc adm policy scc-subject-review -f -
$ oc -n openshift-nfs-storage adm policy add-scc-to-user hostmount-anyuid -z nfs-client-provisioner

Check the Deployment
oc get all -n openshift-nfs-storage

NAME                                         READY   STATUS    RESTARTS   AGE
pod/nfs-client-provisioner-94d685f65-nhgl8   1/1     Running   0          87s

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nfs-client-provisioner   1/1     1            1           87s

NAME                                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nfs-client-provisioner-94d685f65   1         1         1       87s

Using the NFS Storage Class

To use the NFS volume, simply create a PVC informing storageClassName managed-nfs-storage.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: testing
  namespace: ProjectName
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: managed-nfs-storage
  volumeMode: Filesystem
oc get pvc
NAME      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE
testing   Bound    pvc-452aab67-c094-40ff-80f8-0e71313b2c75   1Gi        RWO            managed-nfs-storage   97s

A PV will be created automatically, consuming space on the NFS server.

oc get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                             STORAGECLASS          REASON   AGE
pvc-452aab67-c094-40ff-80f8-0e71313b2c75   1Gi        RWO            Delete           Bound    ProjectName/testing                                managed-nfs-storage            2m34s

How easy is that? 😃


Did you like the content? Check out these other interesting articles! 🔥



Could you help?

Please support this content by clicking on one of our advertisers’ banners. ❤️

comments powered by Disqus