Setting the naming rules for subdirectories in the NFS Shared Storage Class

Feature Overview

Each PersistentVolumeClaim (PVC) created using the NFS Shared Storage Class corresponds to a subdirectory within the NFS share. By default, subdirectories are named using the pattern ${pv.metadata.name} (i.e., the PersistentVolume name). If the default generated name does not meet your requirements, you can customize the subdirectory naming rules. This document provides configuration methods and best practices for customizing the naming convention.

Use Cases

On the NFS Server side, the subdirectory names can be used to identify their corresponding PersistentVolumeClaims (PVCs) in Kubernetes. This allows administrators to monitor the storage usage of each PVC, thereby simplifying operational management.

Prerequisites

  • An NFS server must be configured, and its access methods must be obtained. Currently, the platform supports three NFS protocol versions: v3, v4.0, and v4.1. You can execute nfsstat -s on the server side to check the version information.

Procedure

Deploying the NFS Shared Storage Plugin

Refers to Deploying the NFS Shared Storage Plugin.

Creating an NFS Shared Storage Class

  1. Refers to Creating an NFS Shared Storage Class.

  2. Before clicking Create, switch to the YAML view and add the subDir configuration under the parameters section to define the naming rules for subdirectories.

    Configuration Example
    Subdirectory Naming Examples
    parameters:
      subDir: ${pvc.metadata.namespace}_${pvc.metadata.name}_${pv.metadata.name}
    

    Note:

    • The subDir field supports only the following three variables, which the NFS CSI Driver automatically resolves:
      • ${pvc.metadata.namespace}: PVC Namespace.
      • ${pvc.metadata.name}: PVC Name.
      • ${pv.metadata.name}: PV Name.
    • The subDir naming rule MUST guarantee unique subdirectory names. Otherwise, multiple PVCs may share the same subdirectory, causing data conflicts.

    Recommended Configurations:

    • ${pvc.metadata.namespace}_${pvc.metadata.name}_${pv.metadata.name}

    • <cluster-identifier>_${pvc.metadata.namespace}_${pvc.metadata.name}_${pv.metadata.name}

      Designed for multiple Kubernetes clusters sharing the same NFS Server, this configuration ensures clear cluster differentiation by incorporating a cluster-specific identifier (e.g., the cluster name) into the subdirectory naming rules.

    Not Recommended Configurations:

    • ${pvc.metadata.namespace}-${pvc.metadata.name}-${pv.metadata.name}

      Avoid - as separators, may lead to ambiguous subdirectory names. For example: If two PVCs are named ns-1/test and ns/1-test, both could generate the same subdirectory ns-1-test.

    • ${pvc.metadata.namespace}/${pvc.metadata.name}/${pv.metadata.name}

      Do NOT configure subDir to create nested directories. The NFS CSI Driver only deletes the last-level directory ${pv.metadata.name} when a PVC is removed, leaving orphaned parent directories on the NFS Server.

  3. click Create.

INFO

Existing StorageClass cannot be modified.