NFS
One of the most useful volume types in Kubernetes is nfs
NFS stands for Network File System-it is a shared file system that can be accessed over the network
NFS must already exist-Kubernetes does not run NFS, pods can only access it
NFS is useful for two reasons:
1.When the Pod is destroyed, the content already stored in NFS will not be deleted. Data is persistent
2.An NFS can be accessed from multiple pods at the same time. NFS can be used to share data between Pods
This is useful for running applications that require a file system shared between multiple application servers
NFS installation example
1. All nodes install nfs
$ yum install -y nfs-common nfs-utils
2. Create a shared directory (master node)
$ mkdir -p /data/nfsdata
3. Authorized shared directory (master node)
$ chmod -R 777 /data/nfsdata
4. Modify the esports file (master node)
$ cat /etc/exports
/data/nfsdata *(rw,no_root_squash,no_all_squash,sync)
5. The configuration takes effect (master node)
$ exportfs -f
6. Start rpc and nfs (in order) (master node)
$ systemctl start rpcbind
$ systemctl start nfs
$ systemctl enable rpcbind #boot start
$ systemctl enable nfs #boot start
7. Check whether it works (master node)
$ showmount -e
Export list for k8s-master: /data/nfsdata *
Create PV, PVC
PV configuration file

capacityspecifies the capacity of the PV as 1GaccessModesspecifies the access mode asReadWriteOnceReadWriteOnce-PV can be mounted to a single node in read-write modeReadOnlyMany-PV can be mounted to multiple nodes in read-only modeReadWriteMany-PV can be mounted to multiple nodes in read-write mode
persistentVolumeReclaimPolicyspecifies when the PV recycling policy isRecycleRetain-requires the administrator to manually recycleRecycle-Clear the data in the PV, the effect is equivalent to executingrm -rf /thevolume/*Delete-Delete the corresponding storage resources on the Storage Provider, such as AWS EBS, GCE PD, Azure Disk, OpenStack Cinder Volume, etc.
storageClassNamespecifies the class of PV asnfs. It is equivalent to setting a category for PV, PVC can specify the class to apply for the PV of the corresponding class- Specify the corresponding directory of the PV on the NFS server

STATUSisAvailablewhich means it is ready and can be bound byPVC
Create PVC

- The access mode must be the same as PV
- Bind the PV class
- Specify the required capacity (< PV capacity)


STATUS is Bound, indicating successful binding of PV
use

Post comment 取消回复