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-utils2. Create a shared directory (master node)
$ mkdir -p /data/nfsdata3. Authorized shared directory (master node)
$ chmod -R 777 /data/nfsdata4. 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 -f6. Start rpc and nfs (in order) (master node)
$ systemctl start rpcbind
$ systemctl start nfs
$ systemctl enable rpcbind #boot start
$ systemctl enable nfs #boot start7. 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 1G
- accessModesspecifies the access mode as- ReadWriteOnce- ReadWriteOnce-PV can be mounted to a single node in read-write mode
- ReadOnlyMany-PV can be mounted to multiple nodes in read-only mode
- ReadWriteMany-PV can be mounted to multiple nodes in read-write mode
 
- persistentVolumeReclaimPolicyspecifies when the PV recycling policy is- Recycle- Retain-requires the administrator to manually recycle
- Recycle-Clear the data in the PV, the effect is equivalent to executing- rm -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 as- nfs. 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

- STATUSis- Availablewhich means it is ready and can be bound by- PVC
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 取消回复