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

image.png

  1. capacity specifies the capacity of the PV as 1G
  2. accessModes specifies 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
  3. persistentVolumeReclaimPolicy specifies 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.
  4. storageClassName specifies 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
  5. Specify the corresponding directory of the PV on the NFS server

image.png

  1. STATUS is Available which means it is ready and can be bound by PVC

Create PVC

image.png

  1. The access mode must be the same as PV
  2. Bind the PV class
  3. Specify the required capacity (< PV capacity)

image.png

image.png

STATUS is Bound, indicating successful binding of PV

use

image.png

Likes(0)

Comment list count 0 Comments

No Comments