Help Center/ Cloud Container Engine/ User Guide (Paris Regions)/ Storage/ Scalable File Service (SFS)/ Using an Existing SFS File System Through a Static PV
Updated on 2024-01-26 GMT+08:00

Using an Existing SFS File System Through a Static PV

SFS is a network-attached storage (NAS) that provides shared, scalable, and high-performance file storage. It applies to large-capacity expansion and cost-sensitive services. This section describes how to use an existing SFS file system to statically create PVs and PVCs and implement data persistence and sharing in workloads.

Prerequisites

  • You have created a cluster and installed the CSI add-on (everest) in the cluster.
  • If you want to create a cluster using commands, use kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.
  • You have created an SFS file system that is in the same VPC as the cluster.

Constraints

  • Multiple PVs can use the same SFS or SFS Turbo file system with the following restrictions:
    • If multiple PVCs/PVs use the same underlying SFS or SFS Turbo file system, when you attempt to mount these PVCs/PVs to the same pod, all PVCs cannot be mounted to the pod and the pod startup fails. This is because the volumeHandle values of these PVs are the same.
    • The persistentVolumeReclaimPolicy parameter in the PVs must be set to Retain. Otherwise, when a PV is deleted, the associated underlying volume may be deleted. In this case, other PVs associated with the underlying volume malfunction.
    • When the underlying volume is repeatedly used, enable isolation and protection for ReadWriteMany at the application layer to prevent data overwriting and loss.

(kubectl) Using an Existing SFS File System

  1. Use kubectl to connect to the cluster.
  2. Create a PV.

    1. Create the pv-sfs.yaml file.
      SFS Capacity-Oriented:
      apiVersion: v1
      kind: PersistentVolume
      metadata:
        annotations:
          pv.kubernetes.io/provisioned-by: everest-csi-provisioner
          everest.io/reclaim-policy: retain-volume-only      # (Optional) The PV is deleted while the underlying volume is retained.
        name: pv-sfs    # PV name.
      spec:
        accessModes:
        - ReadWriteMany      # Access mode. The value must be ReadWriteMany for SFS.
        capacity:
          storage: 1Gi     # SFS volume capacity.
        csi:
          driver: disk.csi.everest.io   # Dependent storage driver for the mounting.
          fsType: nfs
          volumeHandle: <your_volume_id>   # SFS Capacity-Oriented volume ID.
          volumeAttributes:
            everest.io/share-export-location: <your_location>  # Shared path of the SFS volume.
            storage.kubernetes.io/csiProvisionerIdentity: everest-csi-provisioner
        persistentVolumeReclaimPolicy: Retain    # Reclaim policy.
        storageClassName: csi-nas               # Storage class name. csi-nas indicates that SFS Capacity-Oriented is used.
        mountOptions: []                         # Mount options.
      Table 1 Key parameters

      Parameter

      Mandatory

      Description

      everest.io/reclaim-policy: retain-volume-only

      No

      Optional.

      Currently, only retain-volume-only is supported.

      This field is valid only when the everest version is 1.2.9 or later and the reclaim policy is Delete. If the reclaim policy is Delete and the current value is retain-volume-only, the associated PV is deleted while the underlying storage volume is retained, when a PVC is deleted.

      volumeHandle

      Yes

      • If an SFS Capacity-Oriented volume is used, enter the volume ID.

        Log in to the console, choose Service List > Storage > Scalable File Service, and select SFS Turbo. In the list, click the name of the target SFS file system. On the details page, copy the content following ID.

      everest.io/share-export-location

      Yes

      Shared path of the file system.

      • For an SFS Capacity-Oriented file system, log in to the console, choose Service List > Storage > Scalable File Service, and obtain the shared path from the Mount Address column.

      mountOptions

      Yes

      Mount options.

      If not specified, the following configurations are used by default. For details, see Configuring SFS Volume Mount Options.

      mountOptions:
      - vers=3
      - timeo=600
      - nolock
      - hard

      persistentVolumeReclaimPolicy

      Yes

      A reclaim policy is supported when the cluster version is or later than 1.19.10 and the everest version is or later than 1.2.9.

      The Delete and Retain reclaim policies are supported. For details, see PV Reclaim Policy. If multiple PVs use the same SFS volume, use Retain to avoid cascading deletion of underlying volumes.

      Delete:

      • If everest.io/reclaim-policy is not specified, both the PV and SFS volume are deleted when a PVC is deleted.
      • If everest.io/reclaim-policy is set to retain-volume-only set, when a PVC is deleted, the PV is deleted but the SFS volume resources are retained.

      Retain: When a PVC is deleted, the PV and underlying storage resources are not deleted. Instead, you must manually delete these resources. After that, the PV is in the Released status and cannot be bound to the PVC again.

      storage

      Yes

      Requested capacity in the PVC, in Gi.

      For SFS, this field is used only for verification (cannot be empty or 0). Its value is fixed at 1, and any value you set does not take effect for SFS file systems.

    2. Run the following command to create a PV:
      kubectl apply -f pv-sfs.yaml

  3. Create a PVC.

    1. Create the pvc-sfs.yaml file.
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: pvc-sfs
        namespace: default
        annotations:
          volume.beta.kubernetes.io/storage-provisioner: everest-csi-provisioner
      spec:
        accessModes:
        - ReadWriteMany               # The value must be ReadWriteMany for SFS.
        resources:
          requests:
            storage: 1Gi               # SFS volume capacity.
        storageClassName: csi-nas     # Storage class name, which must be the same as the PV's storage class.
        volumeName: pv-sfs    # PV name.
      Table 2 Key parameters

      Parameter

      Mandatory

      Description

      storage

      Yes

      Requested capacity in the PVC, in Gi.

      The value must be the same as the storage size of the existing PV.

      volumeName

      Yes

      PV name, which must be the same as the PV name in 1.

    2. Run the following command to create a PVC:
      kubectl apply -f pvc-sfs.yaml

  4. Create an application.

    1. Create a file named web-demo.yaml. In this example, the SFS volume is mounted to the /data path.
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: web-demo
        namespace: default
      spec:
        replicas: 2
        selector:
          matchLabels:
            app: web-demo
        template:
          metadata:
            labels:
              app: web-demo
          spec:
            containers:
            - name: container-1
              image: nginx:latest
              volumeMounts:
              - name: pvc-sfs-volume    # Volume name, which must be the same as the volume name in the volumes field.
                mountPath: /data  # Location where the storage volume is mounted.
            imagePullSecrets:
              - name: default-secret
            volumes:
              - name: pvc-sfs-volume    # Volume name, which can be customized.
                persistentVolumeClaim:
                  claimName: pvc-sfs    # Name of the created PVC.
    2. Run the following command to create an application to which the SFS volume is mounted:
      kubectl apply -f web-demo.yaml

      After the workload is created, the data in the container mount directory will be persistently stored. Verify the storage by referring to Verifying Data Persistence and Sharing.

Verifying Data Persistence and Sharing

  1. View the deployed applications and files.

    1. Run the following command to view the created pod:
      kubectl get pod | grep web-demo
      Expected output:
      web-demo-846b489584-mjhm9   1/1     Running   0             46s
      web-demo-846b489584-wvv5s   1/1     Running   0             46s
    2. Run the following commands in sequence to view the files in the /data path of the pods:
      kubectl exec web-demo-846b489584-mjhm9 -- ls /data
      kubectl exec web-demo-846b489584-wvv5s -- ls /data

      If no result is returned for both pods, no file exists in the /data path.

  2. Run the following command to create a file named static in the /data path:

    kubectl exec web-demo-846b489584-mjhm9 --  touch /data/static

  3. Run the following command to view the files in the /data path:

    kubectl exec web-demo-846b489584-mjhm9 -- ls /data

    Expected output:

    static

  4. Verify data persistence.

    1. Run the following command to delete the pod named web-demo-846b489584-mjhm9:
      kubectl delete pod web-demo-846b489584-mjhm9

      Expected output:

      pod "web-demo-846b489584-mjhm9" deleted

      After the deletion, the Deployment controller automatically creates a replica.

    2. Run the following command to view the created pod:
      kubectl get pod | grep web-demo
      The expected output is as follows, in which web-demo-846b489584-d4d4j is the newly created pod:
      web-demo-846b489584-d4d4j   1/1     Running   0             110s
      web-demo-846b489584-wvv5s    1/1     Running   0             7m50s
    3. Run the following command to check whether the files in the /data path of the new pod have been modified:
      kubectl exec web-demo-846b489584-d4d4j -- ls /data

      Expected output:

      static

      If the static file still exists, the data can be stored persistently.

  5. Verify data sharing.

    1. Run the following command to view the created pod:
      kubectl get pod | grep web-demo
      Expected output:
      web-demo-846b489584-d4d4j   1/1     Running   0             7m
      web-demo-846b489584-wvv5s   1/1     Running   0             13m
    2. Run the following command to create a file named share in the /data path of either pod: In this example, select the pod named web-demo-846b489584-d4d4j.
      kubectl exec web-demo-846b489584-d4d4j --  touch /data/share
      Check the files in the /data path of the pod.
      kubectl exec web-demo-846b489584-d4d4j -- ls /data

      Expected output:

      share
      static
    3. Check whether the share file exists in the /data path of another pod (web-demo-846b489584-wvv5s) as well to verify data sharing.
      kubectl exec web-demo-846b489584-wvv5s -- ls /data

      Expected output:

      share
      static

      After you create a file in the /data path of a pod, if the file is also created in the /data path of another pods, the two pods share the same volume.

Related Operations

You can also perform the operations listed in Table 3.
Table 3 Related operations

Operation

Description

Procedure

Viewing events

You can view event names, event types, number of occurrences, Kubernetes events, first occurrence time, and last occurrence time of the PVC or PV.

  1. Choose Storage from the navigation pane, and click the PersistentVolumeClaims (PVCs) or PersistentVolumes (PVs) tab.
  2. Click View Events in the Operation column of the target PVC or PV to view events generated within one hour (event data is retained for one hour).

Viewing a YAML file

You can view, copy, and download the YAML files of a PVC or PV.

  1. Choose Storage from the navigation pane, and click the PersistentVolumeClaims (PVCs) or PersistentVolumes (PVs) tab.
  2. Click View YAML in the Operation column of the target PVC or PV to view or download the YAML.