Create NFS dynamic provisioner for Openshift. Use nfs for dynamic provisioning with OCP 3.11
I will explain how to install NFS server on Centos 7.X and and configure openshift to use this NFS share as Persistent Volume
nfs-client from kubernetes-incubator project is an automatic provisioner that use your existing and already configured NFS server to support dynamic provisioning of Kubernetes/OpenShift Persistent Volumes via Persistent Volume Claims.
Install NFS Server
Create a Centos/RHEL 7 based instance and run the following commands as root
yum install -y nfs-utils
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-servermkdir /var/nfsshare
chmod -R 755 /var/nfssharefirewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --reload
To allow all clients put *
# vi /etc/exports
/var/nfsshare *(rw,sync,no_root_squash)
or you can limit to a subnet/IP
/var/nfsshare 172.16.2.0/24(rw,sync,no_root_squash)
# systemctl restart nfs-server
Install nfs-utils package on all openshift nodes
yum install -y nfs-utils
Download kubernetes-incubator
Login to openshift master instance as origin user (or other user you used to deploy openhift)
$ curl -L -o kubernetes-incubator.zip https://github.com/kubernetes-incubator/external-storage/archive/master.zip
unzip kubernetes-incubator.zip
$ cd external-storage-master/nfs-client/
Change default namespace with current project/namespace. If you are in different project right now. Please switch to target project before running the commands below:
$ NAMESPACE=`oc project -q`
$ sed -i'' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/rbac.yaml
Create the service account and role bindings.
$ oc create -f deploy/rbac.yaml
Allow run as root and mount permission to nfs-client-provisioner. To grant this permission, you must be logged in to openshift with admin privileges.
$ oc adm policy add-scc-to-user hostmount-anyuid system:serviceaccount:$NAMESPACE:nfs-client-provisioner
edit deploy/deployment.yaml
Change the following parameters with yours <YOUR NFS SERVER HOSTNAME> It is 172.16.2.5 in my case and change /var/nfs with /var/nfsshare
which we configured above. Also You don’t have to change PROVISIONER_NAME value fuseim.pri/ifs but it is good to change with your enviroment. for example myproject/nfs
— name: PROVISIONER_NAME
value: fuseim.pri/ifs
— name: NFS_SERVER
value: 172.16.2.5
— name: NFS_PATH
value: /var/nfsshare
volumes:
— name: nfs-client-root
nfs:
server: 172.16.2.5
path: /var/nfsshare
Edit deploy/class.yaml file
set provisioner: fuseim.pri/ifs value as you defined PROVISIONER_NAME in deploy/deployment.yaml (myproject/nfs). It must match PROVISIONER_NAME otherwise it will fail!
class.yaml defines the NFS-Client’s Kubernetes Storage Class with name: managed-nfs-storage
We will define this storage-class name in claim yaml files later.
Deploy and create storage class
$ oc create -f deploy/class.yaml
$ oc create -f deploy/deployment.yaml
Check nfs-client-provisioner pod. Ensure that nfs-client-provisioner is running.
$ oc get pods
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-6f59b7b5f4-sd7r2 1/1 Running 2 1h
Check the logs if there is a failure. If you don’t add hostmount-anyuid above, it will never work! Please double check it if you see an issue.
$ oc logs nfs-client-provisioner-6f59b7b5f4-sd7r2
Now we can create claim and test pod. You don’t have to mount NFS share on openshift master or nodes. nfs-client-provisioner will do it automatically and on demand.
Create a test claim
$ oc create -f deploy/test-claim.yaml
Check the claim status
$ oc get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-claim Bound pvc-88cb0c46–2617–11e9–87e4–000d3a444ea0 1Mi RWX managed-nfs-storage 2h
If you see Pending, it means there is something wrong with NFS sharing or nfs-client-provisioner deployment!
$ cat test-claim.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
annotations:
volume.beta.kubernetes.io/storage-class: “managed-nfs-storage”
spec:
accessModes:
— ReadWriteMany
resources:
requests:
storage: 1Mi
Whenever you create a new claim, you must add
volume.beta.kubernetes.io/storage-class: “managed-nfs-storage” annotation into metadata of the claim yaml to reference the NFS share.
Create the pod with uses test-claim
$ oc create -f test-pod.yaml
pod/test-pod created
Lets check NFS server sharing for SUCCESS file created by test pod.
nfsserver $ ls -l /var/nfsshare/
total 0
drwxrwxrwx. 2 root root 21 Feb 1 14:13 myproject-test-claim-pvc-88cb0c46–2617–11e9–87e4–000d3a444ea0# ls -l /var/nfsshare/myproject-test-claim-pvc-88cb0c46-2617-11e9-87e4-000d3a444ea0/
total 0
-rw-r--r--. 1 root root 0 Feb 1 14:13 SUCCESS
[root@dev-reverse-proxy-1 ~]#
All done!
Comments
Post a Comment