This example deals with creating a persistant volume and sharing the volume with one or more PODs
Some points to keep in mind
- persistant volume (pv) in openshift is using nfs storage in this example
- volumeName attribute in PVC ensures that, pvc always binds to a specific PV
yum install -y nfs-utils
mkdir /nfsshare && mkdir /nfsshare/pv01 && mkdir /nfsshare/pv02 && mkdir /nfsshare/pv03
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
chown -R nfsnobody:nfsnobody /nfsshare
for k in {4..50}; do mkdir -p /nfsshare/pv$k; done
for k in {4..50}; do echo '/nfsshare/pv'${k}' *(rw,root_squash,no_wdelay,sync)'; done
setsebool -P virt_sandbox_use_nfs 1 #on all nodes
setsebool -P virt_use_nfs 1 #on all nodes
systemctl restart nfs-server
showmount -eoc create -f pv.yml #update server attribute based on your nfs server
oc create -f pvc.ymlIm using same pvc "claim1" in both pods
oc create -f pv-pod1.yml
oc create -f pv-pod2.ymlIf i ssh into one pod and change contents of /var/www/html, it should effect other pod /var/www/html
for k in {4..50}; do mkdir -p /nfsshare/pv$k; done
for k in {4..50}; do echo '/nfsshare/pv'${k}' *(rw,root_squash)'; done
systemctl restart nfs-serverfor k in {4..50}
do
cat <<EOF>> pv.yaml
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
name: "pv$k"
spec:
capacity:
storage: "1Gi"
accessModes:
- "ReadWriteMany"
- "ReadWriteOnce"
nfs:
path: "/nfsshare/pv$k"
server: "35.161.240.37"
persistentVolumeReclaimPolicy: "Recycle"
EOF
oc create -f pv.yaml
donefirewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload