All Products
Search
Document Center

Elastic Container Instance:Configure elastic container instances to use a fixed IP address

Last Updated:Mar 07, 2024

By default, the IP address of an elastic container instance is released when the instance is released. If your business scenario requires that elastic container instances use a consistent IP address, you can enable the using a fixed IP address feature. If you enable the feature for an elastic container instance, the IP address of the instance is temporarily retained after the instance is released. During the validity period of the IP address, the system assigns the IP address to the newly created instance. This ensures instances of the same business can use a fixed IP address. This topic describes how to configure elastic container instances to use a fixed IP address.

Feature description

By default, the system randomly assigns an IP address to an elastic container instance from the specified vSwitch CIDR block when you create the instance. If the instance is released, the IP address is also released and new instances are assigned new IP addresses. In some business scenarios, such as scenarios in which the IP address of the service is exposed, instances need to use a fixed IP address. If the instances use different IP addresses, the business is affected.

For the preceding scenarios, Elastic Container Instance supports the using a fixed IP address feature. If you enable this feature when you create an elastic container instance, the system assigns two IP addresses from the specified vSwitch CIDR block. One IP address is a dynamic internal IP address, which is imperceptible to you. The other IP address is a fixed IP address. After the instance is released, the system retains the fixed IP address. Within the validity period (48 hours by default), if the name and vSwitch of the instances that you want to create and the released instance are the same and the feature of using the fixed IP address is enabled for the original instance, the system assigns the retained IP address to the new instances. This way, the instances that meet the same business requirements use the same IP address.

Configuration description

When you call the CreateContainerGroup API operation to create an elastic container instance, you can use parameters such as FixedIp to enable the feature of using the fixed IP address. The following table describes the parameters that you can use. For more information, see CreateContainerGroup.

Parameter

Type

Example

Description

VSwitchId

String

vsw-bp1xpiowfm5vo8o3c****

The ID of the vSwitch to which the instance is connected.

If you want to enable the feature of using a fixed IP address, you must specify this parameter.

SecurityGroupId

String

sg-2ze468xqmne3u4ak*

The ID of the security group to which the instance belongs.

If you specify a vSwitch, you must also specify a security group.

FixedIp

string

true

Specifies whether to configure the instance to use a fixed IP address.

FixedIpRetainHour

integer

24

The retention period of the fixed IP address after the original instance is released and the fixed IP address becomes idle. Unit: hours. Default value: 48.

Configuration example

  1. Create an elastic container instance named Instance A and enable the feature of using the fixed IP address for the instance.

    The following example shows the parameters that are configured to call the CreateContainerGroup API operation to create Instance A:

    RegionId=cn-beijing
    SecurityGroupId=sg-bp1daxpbz9lzpvvc****
    VSwitchId=vsw-bp1gds63lmlm7ib05****
    ContainerGroupName=test
    Container.1.Name=nginx1
    Container.1.Image=registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2
    FixedIp=true
  2. Check the IP address of Instance A.

    You can call the DescribeContainerGroups API operation based on the returned instance ID to check the IP address of Instance A. You can also view the IP address of Instance A in the Elastic Container Instance console.

    API固定IP..png

  3. Delete Instance A.

  4. Create an elastic container instance named Instance B.

    The following example shows the parameters that are configured to call the CreateContainerGroup API operation to create Instance B. The instance name and vSwitch configured for Instance B are the same as the instance name and vSwitch of Instance A, and the feature of using the fixed IP address is enabled for Instance B.

    RegionId=cn-beijing
    SecurityGroupId=sg-bp1daxpbz9lzpvvc****
    VSwitchId=vsw-bp1gds63lmlm7ib05****
    ContainerGroupName=test
    Container.1.Name=nginx2
    Container.1.Image=registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.15.10
    FixedIp=true
  5. Check whether the IP address of Instance B is the same as the IP address of Instance A.

    API固定IP2..png