All Products
Search
Document Center

Specify multiple zones to create an elastic container instance

Last Updated: Jun 11, 2021

In specific cases, you may need to create a large number of elastic container instances to handle bursts of traffic or process jobs. Resources of the specified instance type may be insufficient within the specified zone or the specified vSwitch may have exhausted all of its IP addresses. In these cases, the elastic container instances cannot be created. To ensure that resources are sufficient to create the elastic container instances, you can specify multiple zones.

Prerequisites

vSwitches are created in different zones of the virtual private cloud (VPC) where you want to create an elastic container instance.

  • For information about how to create a vSwitch, see the "Create a vSwitch" section in Work with vSwitches.

  • For information about the regions and zones where Elastic Container Instance is available, see Regions and zones.

Background information

When you create an elastic container instance (pod), you can specify multiple zones by specifying multiple vSwitches. The system then distributes the request to create the elastic container instance across all the specified zones at random. If requested resources are insufficient within one zone, the system attempts to create the instance in a different zone.

When you specify multiple zones (vSwitches), take note of the following items:

  • The specified vSwitches must belong to the same VPC.

  • You can specify up to 10 vSwitches.

You can specify multiple instance types across multiple zones to further improve the success rate of creating elastic container instances. For information about how to create an elastic container instance by specifying multiple instance types, see Specify multiple instance types to create an elastic container instance.

Kubernetes mode

You can specify multiple zones for a cluster or an elastic container instance.

  • If you specify multiple zones for a cluster, the zone settings take effect on all of the elastic container instances within the cluster.

  • If you specify multiple zones for an elastic container instance, the zone settings take effect only on the elastic container instance.

Different cluster types support different methods with which to specify multiple zones.

  • Specify multiple zones when you create a cluster

    Before you create a cluster, we recommend that you create multiple vSwitches in multiple zones within the VPC in which to create the cluster. When you create the cluster, you can select the VPC and select multiple vSwitches to specify multiple zones. The following figure shows how to create a serverless Kubernetes (ASK) cluster in the ACK console.

    Multiple zones
  • Specify multiple zones for an existing cluster

    You can specify multiple zones by modifying eci-profile or modifying the value of an environment variable based on the version of Virtual Kubelet.

    • Modify eci-profile (The version of Virtual Kubelet is v2.0.0.90-15deb126e-aliyun or later)

      You can modify the eci-profile ConfigMap of an existing cluster and append vSwitch IDs to the data.vSwitchlds field in eci-profile to specify multiple zones. Perform the following steps:

      1. Edit eci-profile.

        kubectl edit cm -n kube-system eci-profile
      2. Modify data.vswitch.

        Append vSwitch IDs. Separate multiple vSwitch IDs with commas (,).

        data:
          enableClusterIp: "true"
          enableHybridMode: "false"
          enablePrivateZone: "false"
          resourceGroupId: ""
          securityGroupId: sg-2ze0b9o8pjjzts4h****
          selectors: ""
          vSwitchIds: vsw-2zeet2ksvw7f14ryz****,vsw-2ze94pjtfuj9vaymf**** 
          vpcId: vpc-2zeghwzptn5zii0w7****
      3. Save the modifications and exit.

    • Modify the value of an environment variable (The version of Virtual Kubelet is earlier than v2.0.0.90-15deb126e-aliyun)

      Note

      We recommend that you upgrade Virtual Kubelet to the latest version to use new features.

      To specify multiple zones, you can modify the value of the ECI_VSWITCH environment variable for a Deployment or StatefulSet based on how you deploy Virtual Kubelet. In the following example, a cluster within which Virtual Kubelet is deployed as a Deployment is used:

      1. Edit the Deployment.

        kubectl -n kube-system edit deployment/virtual-node-controller
      2. Modify ECI_VSWITCH. Save the modifications and exit.

        Append vSwitch IDs to the ECI_VSWITCH environment variable. Separate multiple vSwitch IDs with commas (,).

        - name:  ECI_VSWITCH
          value:  vsw-bp1xpiowfm5vo8o3c****,vsw-bp1rkyjgr1xwoho6k**** 
      3. Save the modifications and exit.

  • Specify multiple zones for an elastic container instance

    You can add annotations to metadata in the configuration file of a pod to specify multiple zones. Add the following annotations:

    • k8s.aliyun.com/eci-vswitch: the IDs of vSwitches used to specify multiple zones.

    • k8s.aliyun.com/eci-schedule-strategy: the cross-zone scheduling policy. Valid values: VSwitchOrdered and VSwitchRandom. VSwitchOrdered indicates that resources are scheduled to create elastic container instances within specified zones in the order that the switches are specified. VSwitchRandom indicates that resources are scheduled to create elastic container instances within specified zones at random.

    Sample code:

    apiVersion: v1
    kind: Pod
    metadata:
      annotations:
        k8s.aliyun.com/eci-vswitch: "vsw-bp1xpiowfm5vo8o3c****,vsw-bp1rkyjgr1xwoho6k****"    #Specify multiple vSwitch IDs.
        k8s.aliyun.com/eci-schedule-strategy: "VSwitchOrdered"   #Specify the cross-zone scheduling policy.
      name: nginx-test
    spec:
      containers:
      - name: nginx
        image: nginx:latest

API mode

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the VSwitchId parameter to specify multiple zones. The following table describes this parameter. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

VSwitchId

String

Yes

vsw-bp1xpiowfm5vo8o3c****,vsw-bp1rkyjgr1xwoho6k****

The IDs of vSwitches. You can specify up to 10 vSwitch IDs at a time. Separate multiple vSwitch IDs with commas (,). Example: vsw-***,vsw-***.

Note

We recommend that you specify multiple instance types across multiple zones to create elastic container instances. You can use the VSwitchId parameter to specify multiple zones and use the InstanceType parameter to specify multiple instance types.

Console mode

When you create an elastic container instance by using the elastic container instance buy page in the Elastic Container Instance console, you can select multiple vSwitches to specify multiple zones.

Multiple zones 1