All Products
Search
Document Center

Elastic Container Instance:Specify a private IP address for an elastic container instance

Last Updated:Sep 13, 2023

In some business scenarios, worker instances need to use a fixed IP address. This topic describes how to specify a private IP address for an elastic container instance when you create the instance.

Feature description

By default, the system randomly assigns a private IP address to an elastic container instance from the vSwitch CIDR block that you configured when you create the pod. In some business scenarios, you may want to specify the private IP addresses of instances. For example, if you want to migrate a service, after you delete the old elastic container instance, you can specify the IP address of the old instance for the new instance. This ensures service continuity.

Limits

The private IP addresses that you specified for pods must be IPv4 addresses.

Configuration description

When you call the CreateContainerGroup API operation to create an elastic container instance, you can use the PrivateIpAddress parameter to specify the private IP address of the instance. The following table describes relevant parameters. For more information, see CreateContainerGroup.

Parameter

Type

Example

Description

VSwitchId

String

vsw-bp1gds63lmlm7ib05****

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

If you want to specify a private IP address for an instance, you must specify a vSwitch.

SecurityGroupId

String

sg-bp1daxpbz9lzpvvc****

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

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

PrivateIpAddress

string

172.16.0.1

A private IP address that belongs to the specified vSwitch CIDR block. Make sure that the IP address is idle.

Configuration example

  1. Specify a private IP address to create an elastic container instance.

    Example: Call the CreateContainerGroup API operation to create an elastic container instance

    {
      "RegionId": "cn-beijing",
      "SecurityGroupId": "sg-2ze1pjtsbqcuykpp****",
      "VSwitchId": "vsw-2ze94pjtfuj9vaymf****",
      "PrivateIpAddress": "172.16.0.1",
      "ContainerGroupName": "test",
      "Container": [
        {
          "Name": "nginx",
          "Image": "registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2"
        }
      ]
    }
  2. Check the private IP address of the instance.

    You can call the DescribeContainerGroups API operation to query the private IP address of the instance based on the returned instance ID. The private IP address is displayed in the IntranetIp parameter. You can also view the private IP address in the Elastic Container Instance console.

    Example:

    指定IP.png