Container Network File System (CNFS) lets you manage NAS file systems as native Kubernetes resources. Use a declarative approach to create, adopt, and mount NAS storage for workloads such as websites and data analytics, with flexible support for data sharing and isolation.
Prerequisites
You have an ACK Pro cluster running version 1.20 or later. To update your cluster, see Manually update an ACK cluster.
CNFS supports version 1.20 when used with kubectl.
Ensure that the storage components meet the following version requirements. To update the components, see Components.
csi-plugin and csi-provisioner: v1.24.11-5221f79-aliyun or later.
storage-operator: v1.26.2-1de13b6-aliyun or later.
You have enabled Apsara File Storage NAS. The following limits apply to NAS file systems. For more information, see Limits.
Only the Capacity, Performance, and Extreme storage types of General-purpose NAS are supported. Extreme Speed NAS is not supported.
The number of NAS file systems you can create per account in a single region is limited.
To use KMS encryption for your NAS file systems, you must enable Key Management Service (KMS). For more information, see Purchase a dedicated KMS instance.
Create a NAS file system
Methods for adding a NAS file system
Choose how to add a NAS file system to your cluster.
Method | Description | Volume provisioning mode | Use cases |
CNFS automatically creates and manages a NAS file system with a fixed configuration for fast mounting. | Dynamic volume |
| |
Method 2: Create and use a NAS file system with custom parameters | CNFS creates a new, customizable NAS file system based on the parameters you specify. |
| Ideal for use cases with specific requirements for performance, encryption, or cost, or that require fine-grained storage control. |
CNFS adopts an existing NAS file system for unified management. |
| For seamlessly integrating an existing NAS file system into your cluster. |
Method 1: Automatically create and use a NAS file system
CNFS automatically creates a NAS file system with a default configuration based on your cluster environment. Encryption is disabled by default. If Capacity NAS is unavailable in the current region, Performance NAS is used instead.
After you create the CNFS resource and StorageClass, workloads can request storage through a PersistentVolumeClaim (PVC), which dynamically provisions a PersistentVolume (PV) on the NAS file system and mounts it to a pod.
kubectl
1. Create a CNFS resource Create a |
|
2. Create a StorageClass Create a | |
3. Create a PersistentVolumeClaim The application requests a storage volume by using a PersistentVolumeClaim (PVC) and references the StorageClass as its configuration template. | |
4. Create an application and mount the PVC After the PVC is created, deploy a sample application, such as a Deployment or StatefulSet, and mount the PV bound to the PVC to the application. |
|
5. Verify the result |
|
Console
1. Create a CNFS resource |
|
2. Create a StorageClass |
|
3. Create a PersistentVolumeClaim |
|
4. Create an application and mount the NAS volume | When you create a Deployment or create a StatefulSet, you can mount a PVC to a container in the Volumes section of the Container page. This example shows how to mount the PVC to the/data path in a container. For Volume Type, select Cloud Volume. For Mount Source, select cnfs-nas-pvc. For Container Path, enter |
Method 2: Create and use a custom NAS file system
Use CNFS to create a NAS file system with custom parameters.
Define a
ContainerNetworkFileSystemresource to provision a new NAS file system.Make the file system available to applications in your cluster by creating a static persistent volume or a storage class.
kubectl
1. Create a custom NAS file system Create a |
|
2. Create a persistent volume or storage class After you create the CNFS resource, choose how applications will access the NAS file system.
| Static provisioningFor more information about persistent volume parameters, see Use a static NAS volume. Dynamic provisioningFor more information about storage class parameters, see Use a dynamic NAS volume. |
3. Create a persistent volume claim Create a persistent volume claim that uses the static persistent volume or the storage class that you created. | Static provisioningDynamic provisioning |
4. Create an application and mount the NAS file system After the persistent volume claim is created, mount it in your application. | |
5. Verify the result |
|
Console
|
|
| PV
Storage class
|
|
|
| When you create a Deployment or create a StatefulSet, you can mount a PVC to a container in the Volumes section of the Container page. This example shows how to mount the PVC to the/data path in a container. For Volume Type, select Cloud Volume. For Mount Source, select cnfs-nas-pvc. For Container Path, enter |
Method 3: Use an existing NAS file system
Use CNFS to adopt an existing NAS file system into your cluster so applications can mount and access it.
kubectl
1. Create a CNFS resource from an existing NAS file system Create a |
|
2. Create a persistent volume or storage class After you create the CNFS resource, choose how applications will access the NAS file system.
| Static provisioningFor more information about persistent volume parameters, see Use a static NAS volume. Dynamic provisioningFor more information about storage class parameters, see Use a dynamic NAS volume. |
3. Create a persistent volume claim Create a persistent volume claim that uses the static persistent volume or the storage class that you created. | Static provisioningDynamic provisioning |
4. Create an application and mount the NAS file system After the persistent volume claim is created, mount it in your application. | |
5. Verify the result |
|
Console
|
|
| PV
Storage class
|
|
|
| When you create a Deployment or create a StatefulSet, you can mount a PVC to a container in the Volumes section of the Container page. This example shows how to mount the PVC to the/data path in a container. For Volume Type, select Cloud Volume. For Mount Source, select cnfs-nas-pvc. For Container Path, enter |
Configuring shared and isolated storage
After you create or onboard a NAS file system, configure it for data sharing or data isolation to match your workload requirements.
Configure a shared NAS volume
To share data between pods, mount the same directory from a NAS file system to multiple pods.
Core mechanism: This method uses a static storage volume. In a persistent volume (PV), the declared
pathis identical to the final path mounted by the Container Storage Interface (CSI). Therefore, when multiple pods mount this static PV by using the same persistent volume claim (PVC), they all access the same storage directory, enabling data sharing.Key configuration: In the pod template (
.spec.template) of your workload, set thepersistentVolumeClaim.claimNameparameter under thevolumesfield to the same PVC name.
1. Create a PV and PVC that point to a specific directory | |
2. Create a sample deployment | |
3. Verify the result |
Configure an isolated NAS volume
To achieve data isolation for scenarios like multi-tenancy, you can provide an independent and isolated storage directory for each pod or group of pods.
Core mechanism: This method uses a dynamic storage volume. In the storage class, the CSI driver automatically creates a separate subdirectory with the same name as the PV under the declared
path. This subdirectory serves as the mount point. As a result, each PVC binds to a separate storage directory, enabling data isolation.Key configuration:
In the storage class associated with the statefulset, use the
volumeAs: subpathparameter (the default value) underparametersto create an isolated subdirectory for each PVC.In the statefulset, define
volumeClaimTemplatesto automatically create and bind a separate PVC for each pod.
1. Create a storage class that supports dynamic subdirectories | |
2. Create a sample statefulset | |
3. Verify the result |
Recommendations for production environments
Data security
Data encryption: When you create a new NAS file system, set
parameterstoencryptType: SSE-KMSin CNFS to enable data encryption at rest on the NAS server and improve data security.Data protection and reclaim policy: The
reclaimPolicyfor CNFS is fixed toRetain. Deleting a CNFS object in Kubernetes does not delete the backend NAS instance. However, the reclaim policy of a PV is defined by its StorageClass. In a production environment, we recommend that you set the policy toRetainto prevent accidental deletion.Recycle bin feature: When you create a NAS, we recommend that you enable the recycle bin feature with the
enableTrashCan: "true"parameter to prevent accidental deletion.Concurrent writes: When multiple Pods mount the same shared storage volume, design your application to prevent concurrent writes to the same file, which can cause data corruption.
Operations and management
Performance isolation: Although isolated storage volumes provide data-level isolation, they all share the IOPS and throughput of the same backend NAS instance. For core applications that require strict I/O performance and stable latency, provision a dedicated NAS file system.
Capacity management: Set
allowVolumeExpansion: truein the StorageClass to expand the directory quota of the storage volume.The
requests.storagevalue in a PVC is used primarily for scheduling decisions and is not the quota limit for the entire NAS file system.Monitoring and alerting: Use container storage monitoring to configure alerts for key metrics such as capacity utilization, IOPS, and throughput to proactively identify capacity or performance bottlenecks.
Cost optimization
Choose the right storage type: Select a NAS type based on your cost and performance requirements. For guidance, see Select a NAS type. For example, Capacity NAS offers a lower price point and is suitable for file sharing or archival workloads that do not require low latency.
Release resources promptly: When an application is decommissioned, clean up unused resources. Confirm whether you need to delete the backend NAS file system to avoid incurring unnecessary costs.
References
Verify shared storage, data isolation, and persistent storage
After mounting the NAS file system, follow these steps to verify that the storage works as expected.
Verify shared and persistent storage for a deployment
Verify data isolation and persistent storage for a StatefulSet
CNFS YAML
Run thekubectl get cnfs/<cnfsName> -o yaml command to view the complete configuration and real-time status of a CNFS object.
This section provides an example of the output from running thekubectl get cnfs/cnfs-nas-filesystem -o yaml command for the scenario described in Method 2.
Sample YAML
Parameters
Resource cleanup
To avoid unexpected charges and ensure data security, follow these steps to release resources that you no longer need.
Delete the workload
Action: Delete all applications that use the relevant PVC, such as deployments and StatefulSets. This action stops the pods and unmounts the storage volumes.
Sample command:
kubectl delete deployment <your-deployment-name>
Delete the PVC
Action: Delete the PVC associated with the application. The outcome of the PV deletion depends on the
reclaimPolicy.Retain(recommended): After you delete the PVC, the data and directory on the backend NAS are preserved.Delete: After you delete the PVC, the bound PV is also deleted. How the backend NAS handles the data and directory depends on thearchiveOnDeleteparameter in theStorageClass."true"(default): Instead of being deleted, the directory and files are renamed toarchived-{pvName}.{timestamp}."false": The data is permanently deleted. This action is irreversible. Use this setting with caution.
Sample command:
kubectl delete pvc <your-pvc-name>
Delete the PV
Action: Delete the PV. This step primarily applies to statically provisioned PVs or PVs that are in the
Releasedstate because their reclaim policy is set toRetain.This action removes only the resource definition from Kubernetes and does not delete the backend NAS data.
Sample command:
kubectl delete pv <your-pv-name>
Delete Kubernetes storage definitions (Optional)
Action: Delete the StorageClass and CNFS objects if they are no longer needed.
This action removes only the resource definitions from Kubernetes and does not delete the backend NAS data.
Sample commands:
kubectl delete sc <your-storageclass-name>,kubectl delete cnfs <your-cnfs-name>
Delete the backend NAS file system
Action: See Delete a file system. This action permanently deletes all data on the NAS and is irreversible. Proceed with caution. Before performing this action, ensure that no workloads depend on this NAS.