All Products
Search
Document Center

Elastic Container Instance:Mount a NAS volume to an elastic container instance

Last Updated:Nov 01, 2024

File Storage NAS (NAS) is a distributed file system provided by Alibaba Cloud. NAS supports shared access and auto scaling. NAS features high reliability and high performance. This topic describes how to mount a NAS volume to an elastic container instance.

Precautions

  • NAS file systems are billed based on usage and support the pay-as-you-go, resource plan, and storage capacity unit (SCU) billing methods. For more information about NAS billing, see Billing overview.

  • The NAS file system and the elastic container instance to which the NAS file system is mounted must be in the same virtual private cloud (VPC).

  • NAS is a shared storage service. A NAS file system can be mounted to multiple instances. If a NAS file system is mounted to multiple instances, the data in the file system is shared by the instances. In this case, an application must be able to synchronize data across the instances when data modifications are made to multiple instances.

  • Do not delete the mount target before you unmount a NAS file system. If you delete the mount target, an operating system hang may occur.

Preparations

Before you mount an Alibaba Cloud File Storage NAS file system to an elastic container instance 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 description (API mode)

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 following part describes the relevant parameters. For more information, see CreateContainerGroup.

Specify the volume to be mounted

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.

To specify a NAS volume, you can specify the following volume type:

  • NFS volumes

    Parameter

    Type

    Example

    Description

    Volume.N.Name

    String

    nas-demo

    The name of volume N.

    Volume.N.Type

    String

    NFSVolume

    Set the value to NFSVolume. The value specifies an NFS volume.

    Volume.N.NFSVolume.Server

    String

    3f9cd4****-na***.cn-shanghai.nas.aliyuncs.com

    The endpoint of the server when you set the Volume.N.Type parameter to NFSVolume.

    If you mount an Alibaba Cloud File Storage NAS file system, set the value to the domain name of the mount target of the NAS file system.

    Volume.N.NFSVolume.Path

    String

    /share

    The path to the NFS volume.

    Volume.N.NFSVolume.ReadOnly

    Boolean

    false

    Specifies whether the permissions on NFS volume N are read-only. Valid values:

    • true: The permissions on NFS volume N are read-only.

    • false: The permissions on NFS volume N are read and write.

    Default value: false.

  • Volume that are mounted by using the FlexVolume plug-in

    Parameter

    Type

    Example

    Description

    Volume.N.Name

    String

    nas-demo

    The name of the volume N.

    Volume.N.Type

    String

    FlexVolume

    Set the value to FlexVolume. The value specifies a volume that is mounted by using the FlexVolume plug-in.

    Volume.N.FlexVolume.Driver

    String

    alicloud/nas

    The driver type when you use the FlexVolume plug-in to mount a volume. The value of alicloud/nas specifies to mount an Alibaba Cloud File Storage NAS file system.

    Volume.N.FlexVolume.Options

    String

    {"server":"3f9cd4****-na***.cn-shanghai.nas.aliyuncs.com","path": "/share","vers":"3","options":"nolock,tcp,noresvport"}

    The options when you set the Volume.N.Type parameter to FlexVolume. Each option is a key-value pair in a JSON string.

    When you use the FlexVolume plug-in to mount a NAS file system to an elastic container instance as a volume, this parameter represents the configuration parameters of the NAS volume. You can configure the following parameters:

    • server: the domain name of the mount target of the NAS volume.

    • path: a subdirectory of the NAS file system. The value must start with a forward slash /.

      • Enter an existing subdirectory of the NAS file system. If the specified subdirectory does not exist, the system automatically creates the subdirectory before the system mounts the NAS volume to the subdirectory.

      • For Extreme NAS, the specified path must start with /share.

      • If you do not set this parameter, the NAS file system is mounted to the root directory.

    • vers: the version number of the NFS protocol based on which the NAS file system is mounted. We recommend that you use NFS v3. Extreme NAS only supports NFS v3.

    • options: custom parameters for NAS volumes. The format of this parameter is xxx,xxx,xxx. Example: 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 directory to which volume N is mounted.

Data under this directory is overwritten by the data on the volume. Make sure that this value is correct.

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:

  • None: The volume mount does not receive subsequent mounts that are mounted to this volume or its subdirectories.

  • HostToContainer: The volume mount receives all subsequent mounts that are mounted to this volume or its subdirectories.

  • Bidirectional: This value has a similar effect as HostToContainer. The volume mount receives all subsequent mounts that are mounted to this volume or its subdirectories. In addition, all volume mounts created by container N are propagated back to the host and to all containers of all elastic container instances that use the same volume.

Default value: None.

Note

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 description (console mode)

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.

Specify the volume to be mounted

  1. In the Container Group Configurations section of the Basic Settings step of the Create Container Group wizard, click Advanced Settings.

  2. In the Storage section, click the NAS Persistence tab and click Add.

  3. Configure parameters for the NAS volume.

    • Name: the name of the NAS volume.

    • Mount Point: the mount target of the NAS file system.

    • Path: the path to the NAS file system.

    • Read-only: the read and write permissions on data in the NAS file system. By default, data can be read from the NAS file system and written into the NAS file system. You can select Read-only based on your business requirements.

    nas

Mount the volume

  1. In the Container Configurations section of the Basic Settings step of the Create Container Group wizard, select a container and click Advanced Settings of the container.

  2. Turn on Storage and click Add.

    You can only add the volumes that you specified in the Container Group Configurations section.

    nas2

Note

If you want to mount volumes to multiple containers, select more containers and repeat the preceding operations.

Configuration example

  1. Create Elastic Container Instance A (Instance A) and mount a NAS volume to Instance A.

    The following example shows the parameters that you need to configure when you call the CreateContainerGroup API operation to create Instance A. For more information, see CreateContainerGroup.

    ContainerGroupName=test-nas-a
    SecurityGroupId=sg-bp1daxpbz9lzpvvc****
    VSwitchId=vsw-bp1gds63lmlm7ib05****
    # Specify the volume to be mounted.
    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
  2. Connect to Instance A and add a file to the mount directory.

    For more information, see Connect to an elastic container instance.

    nas3

  3. Delete Instance A.

  4. Create Elastic Container Instance B (Instance B) and mount the same NAS volume to Instance B.

    ContainerGroupName=test-nas-b
    SecurityGroupId=sg-bp1daxpbz9lzpvvc****
    VSwitchId=vsw-bp1gds63lmlm7ib05****
    # Specify the volume to be mounted.
    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
  5. Connect to Instance B and check whether the files in the mount directory are the same as the files in the mount directory of the NAS volume on Instance A.

    Instance A and Instance B share the same NAS volume, and NAS volumes are persistent storage. After Instance A is deleted, you can use Instance B to obtain the file that you added to the NAS volume by using Instance A.

    nas4