Ok, this is the second part of this post and we talk about mounting the external volume and create a simple PV and PVC in your Kubernetes cluster.
If you followed the first part of this post, maybe notice that every time a node or the full cluster is restarted the mount volume disappears. and you have to mount:
mount 10.1.6.6:/var/nfs/general /mnt/nfs/home
where that IP is your private IP address in case you were working with vm’s.
To set up the volume no mather the VM has to be restarted or deallocated, you have to modify the fstab file.
echo /etc/fstab # # /etc/fstab # Created by anaconda on Fri Sep 20 13:48:33 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=2c32741d-19d6-4f09-bdbc-a28db4e1d338 / xfs defaults 0 0 UUID=efd62c66-c0c1-45b1-848f-ec800f6243e7 /boot xfs defaults 0 0
Fstab is your operating system’s file system table, so we have to add some lines to add a volume.
nano /etc/fstab # # /etc/fstab # Created by anaconda on Fri Sep 20 13:48:33 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=2c32741d-19d6-4f09-bdbc-a28db4e1d338 / xfs defaults 0 0 UUID=efd62c66-c0c1-45b1-848f-ec800f6243e7 /boot xfs defaults 0 0 10.1.6.6:/var/nfs/general/01_mysql /var/nfs/general/01_mysql nfs rw 0 0
we have added this line 10.1.6.6:/var/nfs/general/01_mysql /var/nfs/general/01_mysql nfs rw 0 0 the server IP and the remote folder we are sharing the type of volume “nfs”, grants, if dump and fsck.
According to these column values
file system mount point type options dump pass
Now we have to do this process in each node including the master node.
Finally, we will be able to deploy a new PV and a PVC
This will be our pv.yaml
apiVersion: v1 kind: PersistentVolume metadata: name: kube-pv spec: capacity: storage: 1Gi volumeMode: Filesystem accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Recycle nfs: path: /var/nfs/general server: 10.1.6.6 readOnly: false
and our pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: kube-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi
Basically we have a Persistent Volume with a link between our NFS server so now we are able to say:
kubectl apply -f pv.yaml
kubectl apply -f pvc.yaml
Now you could use your volume in your future services or create new volumes.