All Products
Search
Document Center

Use reserved instances

Last Updated: May 28, 2021

If you run long-lived online applications, we recommend that you use reserved instances to offset the bills of elastic container instances. This topic describes how to use reserved instances to offset the bills of long-lived elastic container instances.

Purchase reserved instances

Reserved instances can match Elastic Compute Service (ECS) instances (excluding preemptible instances) within your account to provide a billing discount. If you use an ECS instance type to create an elastic container instance, you can use reserved instances to offset the bills of the elastic container instance. For more information, see Reserved instance overview.

Reserved instances can be applied only to elastic container instances that were created by specifying ECS instance types. Before you purchase a reserved instance, take note of the following items:

  • Only some ECS instance types can be used to create elastic container instances. Make sure that the selected ECS instance types suit your business needs. For more information, see Specify an ECS instance type to create an elastic container instance.

  • Reserved instances can be applied only to elastic container instances that meet the matching rules. Make sure that your elastic container instances can be matched to the reserved instances.

    Note

    When you purchase reserved instances, you commit to the specified terms and instance types. After a reserved instance is purchased, it automatically matches pay-as-you-go instances that have specific attributes within the term of the reserved instance. You cannot manually manage how the reserved instance is matched to pay-as-you-go instances. After a reserved instance is matched, it checks for eligible pay-as-you-go bills on an hourly basis and deducts fees based on its computing power. For more information, see Match between reserved instances and pay-as-you-go instances.

You can purchase and manage reserved instances on the Reserved Instances page in the ECS console. For more information, see Purchase reserved instances.

  • If you want to optimize the costs of existing elastic container instances, you can find elastic container instances that were created by specifying ECS instance types, and purchase reserved instances of the specified ECS instance types.

  • If you have no existing elastic container instances, select ECS instance types based on your business needs to purchase suitable reserved instances. Then, create elastic container instances based on the selected ECS instance types.

Create elastic container instances

To apply your purchased reserved instances to elastic container instances, you must specify the ECS instance types of the reserved instances when create the elastic container instances.

Kubernetes mode

If you have purchased ecs.c5.large reserved instances, you must specify the ecs.c5.large ECS instance type when you create elastic container instances.

Note

If you are using a Container Service for Kubernetes (ACK) or serverless Kubernetes (ASK) cluster and have purchased a zonal reserved instance, make sure that the reserved instance and the cluster reside within the same zone. Otherwise, the reserved instance cannot be applied to the elastic container instance. If the reserved instance and the elastic container instance are located in different zones of a region, you can change the zonal reserved instance into a regional reserved instance. For more information, see Modify a reserved instance.

You can add annotations to metadata in the configuration file of the pod to specify an ECS instance type to which your reserved instance can be applied. Sample code:

apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment-basic
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        k8s.aliyun.com/eci-use-specs : ecs.c5.large  #Specify an ECS instance type to which your reserved instance can be applied.
    spec:
    #  nodeSelector:
    #    env: test-team
      containers:
      - name: nginx
        image: nginx:1.7.9 # replace it with your exactly <image_name:tags>
        ports:
        - containerPort: 80

API mode

If you have purchased an ecs.c5.large reserved instance, you must set the InstanceType parameter to ecs.c5.large when you call the CreateContainerGroup operation to create an elastic container instance. The following table describes the parameter. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

InstanceType

String

No

ecs.c5.xlarge

The ECS instance types. Specify the ECS instance types to which your reserved instance can be applied. You can specify up to five ECS instance types at a time. Separate multiple instance types with commas (,). Example: ecs.c5.xlarge,ecs.g5.xlarge.

View deduction information of a reserved instance

You can view the billing details of elastic container instances and reserved instances in the Billing Management console.

Notice

In scenarios where multiple zones are specified to create elastic container instances, the created elastic container instances may be located in multiple zones. If you find that a reserved instance is not applied to offset bills as expected, check whether the reserved instance and the elastic container instance are within the same zone. If the reserved instance and the elastic container instance are located in different zones of a region, you can change the zonal reserved instance into a regional reserved instance. For more information, see Modify a reserved instance.

  • View bills of elastic container instances

    On the Bills page, click the Details tab. You can view the consumption details by elastic container instance. No bills are generated for the fees of elastic container instances that are offset by reserved instances.

  • View the bills of reserved instances

    On the Manage Reserved Instances page, you can view the deduction details of the reserved instances.

    The usage details of reserved instances show which elastic container instances had fees deducted by the reserved instances each billing cycle (hour). The deducted duration is calculated by using the following formula: Computing power × Number of hours. Reserved instances are deducted by computing power. One unit of computing power is equivalent to one vCPU.