All Products
Search
Document Center

Auto Scaling:Automatically build and update images of elastic container instances by using Apsara DevOps pipelines

Last Updated:Apr 08, 2025

If your scaling group contains elastic container instances, manually updating their images can be time-consuming and error-prone. To avoid these issues, we recommend using the Apsara DevOps pipeline feature in Auto Scaling. This automates image building, updates, and deployment to your elastic container instances.

Implementation principles

This solution integrates the Apsara DevOps pipeline with Auto Scaling to enable quick image building and deployment across elastic container instances after code updates. Implementation process:

  1. Build: The Apsara DevOps pipeline packages and builds your code from the code repository into a Docker image.

  2. Publish: The Apsara DevOps pipeline then publishes the Docker image to a Container Registry repository.

  3. Update: After publishing, the Apsara DevOps pipeline uses CloudOps Orchestration Service (OOS) to update the image for elastic container instances in your scaling group, including the scaling configuration used for new instances.

For more information about Apsara DevOps, see What is Alibaba Cloud DevOps?

Preparations

If you are using a Resource Access Management (RAM) user, make sure that you have the following permissions. For information about how to grant permissions to a RAM user, see Grant permissions to a RAM user.

Sample custom policy

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ess:*",
                "cr:*",
                "rdc:*",
                "vpc:Describe*",
                "ecs:DescribeSecurityGroups",
                "oos:ListExecutions",
                "oos:ListTaskExecutions",
                "oos:GetExecutionTemplate",
                "eci:Describe*",
                "eci:ListUsage",
                "oss:GetExecutionTemplate",
                "ram:GetRole"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

Configure an environment

To build and deploy an image across elastic container instances in your scaling group, you must complete the following steps:

Step 1: Create an Alibaba Cloud Container Registry repository

Important

If you have an existing Container Registry repository, you can skip this step.

After you create a Container Registry repository, you can store your image in the repository.

  1. Log on to the Container Registry console.

  2. Create a Container Registry instance.

    1. In the top navigation bar, select a Container Registry region.

      Note

      To allow support for domain name-based access over a virtual private cloud (VPC), we recommend that you create a Container Registry repository in the same region as your scaling group. If you create a Container Registry repository in a region that is different from that of your scaling group, you must enable Internet access for the Container Registry repository and elastic container instances in your scaling group.

    2. On the Instances page, click Instance of Personal Edition to create an instance.

      image

    3. After the instance is created, go to the Instance of Personal Edition page and click Reset Docker Login Password.

      image

  3. After you reset the logon password, click Namespace in the left-side navigation pane and then click Create Namespace to create a namespace.

  4. Click Repositories in the left-side navigation pane and then click Create Repository. In the Create Repository dialog box, configure parameters based on your business requirements. The following table describes the parameters.

    • Repository Info

      Parameter

      Description

      Example

      Namespace

      Select the namespace that you created in Step 3.

      ess_eci_test_namespace

      Repository Name

      Enter a custom name for the repository.

      ess_eci_test_repo

      Repository Type

      Select Private.

      Private

      Summary

      Enter the reason for creating the repository.

      test

    • Code Source

      In the Code Source step, select Local Repository and click Create Repository.

  5. After the repository is created, go to the Details page, find the public endpoint, and then copy the endpoint for subsequent use.

Step 2: Create a scaling group of the Elastic Container Instance type

Important

If you have an existing scaling group, you can skip this step.

To create a scaling group, you can use one of the following methods:

  • Create a scaling group by using a YAML file

  • Create a scaling group by using a form

Method 1: Create a scaling group by using a YAML file

  1. Log on to the Auto Scaling console.

  2. In the top navigation bar, select an Auto Scaling region. In the left-side navigation pane, click Scaling Groups. On the Scaling Groups page, click Create.

  3. On the Create by YAML File tab, configure parameters as prompted to create a scaling group and click Create. In this topic, the following YAML file is used. For more information about how to create a scaling group by using a YAML file, see Use Kubernetes YAML files to configure scaling groups of the Elastic Container Instance type.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-demo
      annotations:
        k8s.aliyun.com/ess-scaling-group-name: ess-eci-test
        k8s.aliyun.com/ess-scaling-group-min-size: 0
        k8s.aliyun.com/ess-scaling-group-max-size: 5
    spec:
      selector:
        matchLabels:
          app: nginx-demo
      replicas: 0
      template:
        metadata:
          labels:
            app: nginx-demo
          annotations:
            k8s.aliyun.com/eci-with-eip: false
        spec:
          containers:
            - name: nginx
              image: registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:latest
              ports:
                - containerPort: 80
                  name: http
                - containerPort: 443
                  name: https
              resources:
                requests:
                  memory: 0.05Gi
                  cpu: 50m
                limits:
                  memory: 1Gi
                  cpu: '1'
    Warning

    If you already have an image, replace the image in the sample YAML file with yours. If no image is available, use the sample YMAL file's image. It will be automatically replaced when the pipeline runs. If you do not specify an image, you cannot create the scaling group.

    Parameters

    Parameter

    Description

    Example

    k8s.aliyun.com/ess-scaling-group-name

    The name of the scaling group.

    ess-eci-test

    k8s.aliyun.com/ess-scaling-group-min-size

    The lower limit of the number of instances in the scaling group. If the number of instances in the scaling group is less than the value of this parameter, Auto Scaling automatically creates instances in the scaling group to reach the lower limit.

    0

    k8s.aliyun.com/ess-scaling-group-max-size

    The upper limit of the number of instances in the scaling group. If the number of instances in the scaling group is greater than the value of this parameter, Auto Scaling automatically removes instances from the scaling group until the number of instances drops to the upper limit.

    5

    k8s.aliyun.com/eci-with-eip

    Specifies whether to automatically create elastic IP addresses (EIPs) and associates the EIPs with elastic container instances.

    false

Method 2: Create a scaling group by using a form

  1. Log on to the Auto Scaling console.

  2. In the top navigation bar, select an Auto Scaling region.

  3. Create a scaling group.

    1. In the left-side navigation pane, click Scaling Groups. On the Scaling Groups page, click create.

    2. On the Create by Form tab, configure parameters as prompted to create a scaling group and click Create. The following table describes the parameter settings for this example. Any parameters not included retain the default values. For more information, see Create scaling groups.

      Parameter

      Description

      Example

      Scaling Group Name

      Enter a name for the scaling group.

      ess-eci-test

      Type

      Select ECI, which specifies that the scaling group contains elastic container instances.

      ECI

      Instance Configuration Source

      Do not specify the template for automatically creating elastic container instances at this stage. After you create the scaling group, you must continue to create a scaling configuration.

      Create from Scratch

      Minimum Number of Instances

      If you set this parameter to 1, the scaling group must contain at least one elastic container instance.

      0

      Maximum Number of Instances

      If you set this parameter to 5, the scaling group can contain up to five elastic container instances.

      5

      VPC

      Specify a VPC. Elastic container instances contained in this scaling group reside in this VPC.

      vpc-test****-001

      vSwitch

      Specify multiple vSwitches from different zones to improve the success rate of scale-out operations.

      vsw-test****

  4. Create a scaling configuration for the scaling group.

    1. Find the scaling group that you created and click Details in the Actions column to go to the scaling group details page.

    2. On the Instance Configuration Sources tab, click Scaling Configurations. Then, click Create Scaling Configuration to go to the Create Scaling Configuration page.

    3. Configure parameters as prompted. In the Preview Scaling Configuration dialog box, click Create. Then, click Enable. The following table describes the parameter settings that are used in this example. Any parameters not included retain the default values. For more information about how to create a scaling configuration, see Create a scaling configuration of the Elastic Container Instance type.

      Parameter

      Description

      Example

      Billing Method

      Select a billing method based on your business requirements.

      Pay-as-you-go

      Security Group

      Select a security group based on your business requirements.

      sg-****oer

      Container Configurations > Container Name

      Enter a custom container name.

      nginx

      Container Configurations > Image

      Select an image and image tag based on your business requirements.

      Warning

      If you have an existing image, you can use the existing image. If you do not have an existing image, we recommend that you use the sample image. If you do not specify an image, you cannot create the scaling group.

      • Image name: registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx.

      • Image tag: latest.

    4. On the Scaling Configurations tab, find the scaling configuration that you created and click Apply in the Actions column to enable the scaling configuration.

Step 3: Configure an Apsara DevOps pipeline

You must configure an Apsara DevOps pipeline to automate image package, release, and deployment.

  1. On the scaling group details page, click the Publish Management tab and then click Publish by Using Apsara DevOps.

    image

  2. Select an organization from the Organization to Associate drop-down list and click Next.

    Important

    If no organization is available, click Create Organization to create an organization as prompted. After you create and select an organization, complete the authorization as prompted.

  3. Configure a pipeline.

    1. Configure a pipeline source. In the Pipeline Source section, click + Add and then click Sample Code Source. Then, click Add.

      image

      Note

      If you have your own code repository, you can select the URL of your code repository as prompted.

    2. Add an image build task.

      1. In the Image Building Task section, click + Add.

      2. In the Image Building Task panel, click Create Service Connection in the Select Service Connection section. After the page is displayed, click Create Service Connection.

        image

      3. In the dialog box that appears, select Container Registry (ACR) and click Next. Then, select Authorize Service. If the Authorize Service button does not appear, click Create to go to the authorization page and then click Create.

      4. Go back to the Image Building Task panel. In the Service Connection drop-down list, select the created service connection. In the Image Repository drop-down list, select the created image repository and click Add.

        image

    3. Add a deployment task.

      1. In the Deployment Task section, click + Add. In the Select Service Connection section, click Create Service Connection.

        image

      2. In the dialog box that appears, select Auto Scaling. Click Next and then click Create.

      3. In the Image Deployment section, select Build an image and push it to Alibaba Cloud Image Warehouse Personal Edition.Mirror VPC address and click Add.

        Note

        If your scaling group and the image reside in the same region, we recommend that you select Build an image and push it to Alibaba Cloud Image Warehouse Personal Edition.Mirror VPC address. If you want to pull the image in other cases, make sure that elastic container instances can access the Internet.

    4. Click Create.

Use case: Build and deploy an image

Important

If another RAM user wants to use this feature, make sure that the RAM user belongs to your organization and has the pipeline permissions. The RAM user must also have the following permissions:

  • Permissions to manage Apsara DevOps RDC resources

  • Read-only permissions on RAM resources

  • Permissions to manage OOS resources

After you update your code, click Run on the Publish by Using Apsara DevOps tab to package and deploy the new code to your scaling group.

  1. Complete the following preparations.

    • Configure an environment. For more information, see Configure an environment.

    • Update and push your code to the code repository.

  2. Build and deploy an image with a few clicks.

    1. Go to the scaling group details page. Click the Publish Management tab, click the Publish by Using Apsara DevOps tab, and then click Run. A new record is added to the list of running records.

      image

    2. In the record list, click Details to view the details of the pipeline. Wait until the pipeline is executed. Once the pipeline finishes, your scaling group's elastic container instances and scaling configuration are updated automatically. New instances will use the latest image.

      image

      • On the Instance Configuration Sources tab, find the active scaling configuration and click Edit to check the scaling configuration. Check whether the image in the Container Configurations section is updated.

      • Manually trigger a scale-out event. On the Instances tab, click the newly scaled-out elastic container instance and check whether the instance uses the new image.

      • If the scaling group contains an elastic container instance that is in the Running state, click the name of the instance on the Instances tab to go to the instance details page and check whether the instance image is updated.