OpenShift 4.8 (and above) with NFS Subdir External Provisioner

Why this Tutorial

Why NFS ?

Steps

NFS Server

NFS Packages

# dnf install -y nfs-utils policycoreutils-python-utils policycoreutils
# mkdir /var/nfsshare
# lvcreate -L50G -n nfs vg00
# mkfs.xfs /dev/vg00/nfs
# mount -t xfs /dev/vg00/nfs /var/nfsshare
# cat >> /etc/fstab << EOF
/dev/vg00/nfs /var/nfsshare xfs defaults 0 0
EOF
# chmod 777 /var/nfsshare
# cat > /etc/exports << EOF
/var/nfsshare *(rw,sync,no_wdelay,no_root_squash,insecure,fsid=0)
EOF

Services

# systemctl start nfs-server.service
# systemctl enable nfs-server.service
# systemctl status nfs-server.service

SElinux

# setsebool -P nfs_export_all_rw 1
# setsebool -P nfs_export_all_ro 1
# semanage fcontext -a -t public_content_rw_t  "/var/nfsshare(/.*)?"
# restorecon -R /var/nfsshare

Firewall

# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --permanent --add-service=rpc-bind
# firewall-cmd --permanent --add-service=mountd
# firewall-cmd --reload

Export

# exportfs -arv

Testing

$ mount -t nfs nfs-server:/var/nfsshare /mnt
$ touch /mnt/1 && rm -f /mnt/1

NFS Subdir External Provisioner

namespace

# oc create namespace openshift-nfs-storage
# oc label namespace openshift-nfs-storage "openshift.io/cluster-monitoring=true"
# oc label node <NodeName> cluster.ocs.openshift.io/openshift-storage=''

Clone the repository

# git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner.git nfs-subdir

Configuration updates

# cd nfs-subdir
# oc project openshift-nfs-storage
# NAMESPACE=`oc project -q`
# sed -i'' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/rbac.yaml ./deploy/deployment.yaml
# oc create -f deploy/rbac.yaml
# oc adm policy add-scc-to-user hostmount-anyuid system:serviceaccount:$NAMESPACE:nfs-client-provisioner
env:
- name: PROVISIONER_NAME
value: k8s-sigs.io/nfs-subdir-external-provisioner
- name: NFS_SERVER
value: <YOUR NFS SERVER HOSTNAME>
- name: NFS_PATH
value: /var/nfs
volumes:
- name: nfs-client-root
nfs:
server: <YOUR NFS SERVER HOSTNAME>
path: /var/nfs
env:
- name: PROVISIONER_NAME
value: storage.io/nfs
- name: NFS_SERVER
value: <YOUR NFS SERVER HOSTNAME>
- name: NFS_PATH
value: /var/nfsshare
volumes:
- name: nfs-client-root
nfs:
server: <YOUR NFS SERVER HOSTNAME>
path: /var/nfsshare
# sed -i '' "s/k8s.gcr.io\/sig-storage\/<internal registry>/g" ./deploy/deployment.yaml
# echo 'apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: managed-nfs-storage
provisioner: storage.io/nfs
parameters:
pathPattern: "${.PVC.namespace}/${.PVC.name}"
onDelete: delete' > deploy/class.yaml
# oc create -f deploy/deployment.yaml -f deploy/class.yaml
# oc get pods -n openshift-nfs-storage
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-7894d87997-gqjcq 1/1 Running 0 21h

Testing

# oc create -f deploy/test-claim.yaml -f deploy/test-pod.yaml
# oc delete -f deploy/test-pod.yaml -f deploy/test-claim.yaml
# cat > deploy/pvc.yaml << EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
spec:
storageClassName: managed-nfs-storage
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Mi
EOF
# oc create -f deploy/pvc.yaml

Multiple StorageClass

# oc patch storageclass managed-nfs-storage -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}}'

--

--

Open Source contributer for the past 15 years

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store