NAS is a shared, scalable, highly reliable, and high-performance distributed file system provided by Alibaba Cloud. This topic describes how to mount a NAS volume to an Elastic Container Instance (ECI).
Important notes
-
NAS is billed based on usage and supports pay-as-you-go, resource plans, and SCU billing methods. For more information, see NAS Billing overview.
-
The NAS file system must reside in the same VPC as the instance.
-
NAS provides shared storage. A single NAS file system can be mounted to multiple instances. If multiple instances modify the same data simultaneously, your application must handle data synchronization.
-
Do not delete the NAS mount target before unmounting the NAS volume. Doing so may cause the operating system to become unresponsive.
Preparations
Before using Alibaba Cloud File Storage NAS as a volume, create a NAS file system and a mount target. For more information, see Create a file system and Manage mount targets.
Configuration details (OpenAPI)
When you call the CreateContainerGroup API operation to create an elastic container instance, you can use Volume-related parameters to specify volumes, and then use Container.VolumeMount-related parameters to mount the volumes to containers. The relevant parameters are described below. For more information, see CreateContainerGroup.
Declare a volume
When you use Volume-related parameters to specify volumes, you must first specify the types and names of the volumes. Then, you must configure other Volume-related parameters based on the value of the Volume.N.Type parameter.
You can declare a NAS volume in one of two ways:
-
Mount an NFS-type volume
Name
Type
Example value
Description
Volume.N.Name
String
nas-demo
Volume name.
Volume.N.Type
String
NFSVolume
Set to NFSVolume to create an NFS-type volume.
Volume.N.NFSVolume.Server
String
3f9cd4**-na*.cn-shanghai.nas.aliyuncs.com
NFS server address.
If you use Alibaba Cloud File Storage NAS, this is the mount target address of the NAS file system.
Volume.N.NFSVolume.Path
String
/share
NFS volume path.
Volume.N.NFSVolume.ReadOnly
Boolean
false
Read permission for the NFS volume. Valid values:
-
true: read-only
-
false: read and write
Default value: false.
-
-
Mount a volume using the FlexVolume plug-in
Name
Type
Example value
Description
Volume.N.Name
String
nas-demo
Volume name.
Volume.N.Type
String
FlexVolume
Set to FlexVolume to mount a volume using the FlexVolume plug-in.
Volume.N.FlexVolume.Driver
String
alicloud/nas
Driver type when mounting a volume using the FlexVolume plug-in. Set to
alicloud/nasto mount Alibaba Cloud File Storage NAS.Volume.N.FlexVolume.Options
String
{"server":"3f9cd4**-na*.cn-shanghai.nas.aliyuncs.com","path": "/share","vers":"3","options":"nolock,tcp,noresvport"}
Key-value options for the FlexVolume object, passed as a JSON string.
When mounting NAS using FlexVolume, Options specifies the NAS volume configuration parameters. You can configure the following parameters:
-
server: mount target address of the NAS file system.
-
path: subdirectory under the NAS file system path, starting with
/.-
Enter an existing subdirectory in the NAS file system. If the subdirectory does not exist under the root directory, it will be created before mounting.
-
For Extreme NAS file systems, the subdirectory must start with
/share. -
This parameter is optional. If omitted, the root directory of the NAS file system is mounted by default.
-
-
vers: NFS protocol version used to mount the NAS file system. We recommend using v3. Extreme NAS supports only v3.
-
options: custom mount options for NAS, formatted as "xxx,xxx,xxx", such as
nolock,tcp,noresvport.
-
Mount volumes
After you specify volumes, you can use VolumeMount-related parameters to mount the volumes to containers.
Parameter | Type | Example | Description |
Container.N.VolumeMount.N.Name | String | test-volume | The name of volume N to be mounted to container N. This value is the value of Volume.N.Name. |
Container.N.VolumeMount.N.MountPath | String | /usr/share | The path within the container at which to mount the volume. Data in this directory is obscured by the data on the volume. |
Container.N.VolumeMount.N.SubPath | String | /usr/sub | The subdirectory of the volume. This parameter specifies different subdirectories of the same volume that the instance can mount to different subdirectories of containers. |
Container.N.VolumeMount.N.ReadOnly | Boolean | false | Specifies whether the mount directory is read-only. Default value: false. |
Container.N.VolumeMount.N.MountPropagation | String | None | The mount propagation setting of volume N. Mount propagation allows you to share volumes that are mounted to one container to other containers in the same elastic container instance, or even to other elastic container instances on the same host. Valid values:
Default value: None. |
Volumes can also be mounted to init containers. The required parameters are similar to the parameters in the preceding table. You only need to change Container to InitContainer.
Configuration details (console)
When you create an elastic container instance on the Elastic Container Instance buy page, you can specify volumes in the Container Group Configurations section and then mount the volumes to containers in the Container Configurations section.
Declare a volume
-
In the Container group configuration section, expand Advanced Configuration.
-
Under Storage, select the NAS persistent storage tab and click Add.
-
Configure the NAS volume parameters.
-
Name: name of the NAS volume.
-
Mount target: mount target of the NAS file system.
-
Path: path in the NAS file system to mount.
-
Read-only: data read permission. Read and write is enabled by default. Select read-only as needed.
-
Mount the volume
-
In the Container configuration section, select a container and expand its advanced configuration.
-
Turn on the Storage toggle and click Add.
The available volumes are those declared during container group configuration.
In Select storage, choose the declared volume (for example, nas-demo). Set the storage type to NAS persistent storage. Enter
/datafor Mount path in container and/testfor Subdirectory. Select Read-only as needed.
If you want to mount volumes to multiple containers, select more containers and repeat the preceding operations.
Configuration example
-
Create ECI instance A and mount a NAS volume to it.
The following example shows parameters used to call the CreateContainerGroup operation to create instance A. For more information, see CreateContainerGroup.
ContainerGroupName=test-nas-a SecurityGroupId=sg-bp1daxpbz9lzpvvc**** VSwitchId=vsw-bp1gds63lmlm7ib05**** # Declare a volume Volume.1.Name=nas-demo Volume.1.Type=NFSVolume Volume.1.NFSVolume.Server=3f9cd4****-na***.cn-shanghai.nas.aliyuncs.com Volume.1.NFSVolume.Path=/share # Mount the volume to a container Container.1.Name=nginx Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2 Container.1.VolumeMount.1.Name=nas-demo Container.1.VolumeMount.1.MountPath=/data-a -
Connect to instance A and create a file in the mount directory.
For information about connecting to an ECI instance, see Connect to an ECI instance using Workbench.
root@test-nas-a:/# cd data-a root@test-nas-a:/data-a# ls root@test-nas-a:/data-a# echo "hello" >test root@test-nas-a:/data-a# ls test root@test-nas-a:/data-a# cat test hello -
Delete instance A.
-
Create ECI instance B and mount the same NAS volume to it.
ContainerGroupName=test-nas-b SecurityGroupId=sg-bp1daxpbz9lzpvvc**** VSwitchId=vsw-bp1gds63lmlm7ib05**** # Declare a volume Volume.1.Name=nas-demo Volume.1.Type=FlexVolume Volume.1.FlexVolume.Driver=alicloud/nas Volume.1.FlexVolume.Options={"server":"3f9cd4****-na***.cn-shanghai.nas.aliyuncs.com","path": "/share"} # Mount the volume to a container Container.1.Name=nginx Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2 Container.1.VolumeMount.1.Name=nas-demo Container.1.VolumeMount.1.MountPath=/data-b -
Connect to instance B and verify the file in the mount directory.
Because both instance A and instance B mount the same NAS volume—and NAS provides persistent storage—the file created by instance A remains accessible through instance B after instance A is deleted.
root@test-nas-b:/# cd data-b root@test-nas-b:/data-b# ls test root@test-nas-b:/data-b# cat test hello