Location>code7788 >text

k8s-NFS system configuration

Popularity:796 ℃/2024-10-16 22:26:36

k8s-NFS system configuration

NFS(network filesystem), nfs filesystem is mainly used for persistent storage in k8s, which can be accessed and shared data by multiple pods.

specificities

  1. data persistence
    nfs provides a way for k8s pods to persist data, even if the pod is deleted, the data is not lost, this is because the data exists on the nfs server, not on the pod.
  2. Resource sharing
    Files on the nfs system can be used for multiple pods to share the same data.

NFS server installation-master node

Take centos as an example

# Install the nfs server
yum install nfs-utils -y
# Create a shared directory
mkdir /nfs
# Configure the nfs share
vim /etc/exports
# Add the following line
/nfs *(rw,sync,no_root_squash) # Specify the shared directory and permission settings
# Start the nfs service and set it to start at boot time
systemctl start nfs-server
systemctl enable nfs-server
# Check the status of the nfs server
systemctl status nfs-server
# Start the rpcbind service and set it to start at boot time
systemctl start rpcbind
systemctl enable rpcbind
# Check the status of the rpcbind service
systemctl status rpcbind
# Ensure that the nfs server can be accessed by disabling the firewall.
systemctl stop firewalld
systemctl disable firewalld

NFS client installation-work node

Take centos for example

yum install nfs-utils -y
# Creating a Mount Point,mountnfsenjoy together
mkdir /mnt/nfs
mount -t nfs server_ip:/shared_directory /mnt/nfs
# 自动mount
server_ip:/shared_directory /mnt/nfs nfs defaults 0 0

Explanation of fields

/nfs *(rw,async,no_root_squash)
ro # read-only
rw # read/write
sync # Synchronize writing to memory and hard disk
async # Asynchronous, writes to memory first, then to disk
secure # request source port less than 1024
# User permissions
root_squash # nfs client logs in as root, maps to anonymous user on nfs server
no_root_squash # nfs client logged in as root, maps to nfs server's root user
all_squash # all users mapped to nfs server anonymous user
anonuid=UID # map client user to user ui
anongid=GID # map client user to user gi