Use NFS volumes

Last updated:2021-05-11 10:41:17

You can build a NFS file system by using a KEC instance in the cluster or by creating a KEC instance in the VPC where the cluster resides. You can also use an on-premises NFS file system. NFS is suitable for persistent storage with frequent reads and writes. This topic describes how to build a NFS file system.

Build a NFS file system

Run the following command to install the NFS service on the NFS server:

yum install rpcbind nfs-utils -y
mkdir -p /nfs

Run the following command to configure a shared directory:

cat >/etc/exports<<-EOF
/nfs  172.31.0.0/16(rw,sync,no_root_squash)
EOF

In the preceding command, 172.31.0.0/16(Rw,sync,no_root_squash) indicates that you can read data from and write data to the NFS file system with the root permission from the 172.31.0.0/16 CIDR block. We recommend that you set the access CIDR block to the CIDR block of the VPC where the cluster resides.

Run the following commands to start the service and enable it to automatically start upon startup:

systemctl enable rpcbind
systemctl enable nfs
systemctl start rpcbind
systemctl start nfs

Run the following command to check the configurations:

# exportfs
/nfs            172.31.0.0/16

Install the NFS client

Run the following command to install the NFS client on all nodes in the cluster:

yum install nfs-utils -y

Apply NFS to a Deployment

In the following example, a Deployment containing two replicas is created, and NFS is applied to the Deployment. The IP address of the NFS server is 172.31.22.2.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /usr/share/nginx/html
          readOnly: false
          name: nginx-data
      volumes:
      - name: nginx-data
        nfs:
          server: 172.31.22.2
          path: "/nfs"

Did you find the above information helpful?

Unhelpful
Mostly Unhelpful
A little helpful
Helpful
Very helpful

What might be the problems?

Insufficient
Outdated
Unclear or awkward
Redundant or clumsy
Lack of context for the complex system or functionality

More suggestions

0/200

Please give us your feedback.

Submitted

Thank you for your feedback.

问题反馈