Create Pods across multiple availability zones

更新时间:
复制 MD 格式

Creation failures for ECI pods can occur when you scale your business for traffic bursts or run large-scale jobs. Common causes include insufficient instance inventory in an availability zone or exhausted IP addresses in a vSwitch. To increase the creation success rate and ensure business continuity, create ECI pods across multiple availability zones.

Prerequisites

You must have created multiple vSwitches in different availability zones within the target VPC.

Background information

When you create an ECI instance, you can specify multiple availability zones by providing multiple vSwitches. The system randomly distributes requests across the specified availability zones to balance the load. If an availability zone has insufficient inventory, the system automatically attempts to create the instance in another specified availability zone.

The following limitations apply when you specify multiple availability zones (vSwitches):

  • All specified vSwitches must belong to the same VPC.

  • You can specify a maximum of 10 vSwitches.

Combining multiple availability zones and multiple instance types further increases the instance creation success rate.

Configuration

You can configure multiple availability zones at the cluster level or for a specific ECI pod:

  • Cluster: Specify multiple vSwitches for the cluster. This configuration applies to all ECI pods within the cluster.

  • ECI pod: Specify multiple vSwitches when you create an ECI pod. This configuration applies only to that specific ECI pod.

New cluster configuration

Before you create a cluster, we recommend creating multiple vSwitches in different availability zones within the VPC that you plan to use. When you create the cluster, you can configure multiple vSwitches to enable the multi-availability zone feature. The following example shows how to create an ACK Serverless cluster in the Container Service for Kubernetes (ACK) console.

In the Virtual Private Cloud section, select Use Existing and specify the target VPC. Then, in the vSwitch section, select multiple vSwitches from different availability zones (you can select 1 to 10 vSwitches, and the system marks Recommended availability zones).

Existing cluster configuration

The configuration method depends on the version of VK (the ack-virtual-node component).

  • If your VK version is v2.0.0.90-15deb126e-aliyun or later, modify the eci-profile.

  • If your VK version is earlier than v2.0.0.90-15deb126e-aliyun, modify the environment variable.

Eci-profile

To use multiple availability zones, edit the ConfigMap named eci-profile and append vSwitch IDs to the data.vSwitchIds field.

  1. Edit the eci-profile.

    kubectl edit cm -n kube-system eci-profile
  2. Modify the value of the vSwitchIds field.

    Append the vSwitch IDs, separated by commas.

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

Environment variable

Note

We recommend that you upgrade the VK component to the latest version to use new features.

Depending on how you deployed VK, you can update the ECI_VSWITCH environment variable for the Deployment or StatefulSet to use multiple availability zones. The following example uses a Deployment:

  1. Edit the Deployment.

    kubectl -n kube-system edit deployment/virtual-node-controller
  2. Modify the ECI_VSWITCH environment variable.

    Append vSwitch IDs to the value of the ECI_VSWITCH environment variable. Separate multiple vSwitch IDs with a comma.

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

ECI pod configuration

Use the following annotations in the Pod metadata to specify multiple availability zones:

  • k8s.aliyun.com/eci-vswitch: Specify multiple vSwitches to use multiple availability zones.

    Note

    If an ECI pod uses the k8s.aliyun.com/eci-vswitch annotation, it does not support using a StorageClass of the WaitForFirstConsumer type when mounting a dynamically provisioned disk.

  • k8s.aliyun.com/eci-schedule-strategy: Configures the scheduling policy for multiple availability zones. Valid values are VSwitchOrdered and VSwitchRandom. The following table describes these policies.

    Note

    If you do not specify a multi-availability zone scheduling policy, the VSwitchRandom policy is used by default.

    Scheduling policy

    Description

    VSwitchOrdered (Sequential)

    1. If the ECI pod mounts a disk, the availability zone of the disk must match the availability zone of the Pod. Availability zones that do not meet this requirement are filtered out.

    2. The system attempts to create the resource by trying the specified availability zones in order. If the first availability zone has insufficient inventory, it tries the second, and so on, until the resource is successfully created.

    VSwitchRandom (Inventory-optimized)

    1. If the ECI pod mounts a disk, the availability zone of the disk must match the availability zone of the Pod. Availability zones that do not meet this requirement are filtered out.

    2. Alibaba Cloud selects a suitable vSwitch (and its corresponding availability zone) based on an optimal inventory scheduling strategy.

    3. If the ECI pod specifies an instance type, the scheduler prioritizes availability zones that have a matching reserved instance for that type.

    4. Availability zones with better storage performance are prioritized. The following older availability zones have a lower scheduling priority:

      • cn-beijing-e, cn-beijing-d

      • cn-shenzhen-a, cn-shenzhen-b, cn-shenzhen-c

      • cn-hangzhou-b, cn-hangzhou-e, cn-hangzhou-f

      • cn-shanghai-a, cn-shanghai-c

Important
  • Annotations must be added to the metadata in the configuration file of the pod. For example, when you create a Deployment, you must add annotations in the spec.template.metadata section.

  • Elastic Container Instance-related annotations are only applied when a pod is created. Adding or modifying these annotations on an existing pod will have no effect.

The following is a sample configuration:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      name: nginx-test
      labels:
        app: nginx
        alibabacloud.com/eci: "true" 
      annotations:
        k8s.aliyun.com/eci-vswitch: "vsw-bp1xpiowfm5vo8o3c****,vsw-bp1rkyjgr1xwoho6k****"    # Specify multiple vSwitch IDs.
        k8s.aliyun.com/eci-schedule-strategy: "VSwitchOrdered"   # Configure the multi-availability zone scheduling policy.
    spec:
      containers:
      - name: nginx
        image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
        ports:
        - containerPort: 80

Next steps

If your instance uses a NAT Gateway to connect to the internet, you must update your SNAT entries after specifying multiple vSwitches.

For example, if your existing SNAT entries are configured at the vSwitch level, you must add new entries for the newly added vSwitches. This ensures that ECI instances launched in the new vSwitches can access the internet.