edit-icon download-icon

Container auto scaling

Last Updated: Feb 06, 2018

To meet the demands of applications under different loads, Container Service supports auto scaling for the service, which automatically adjusts the number of containers according to the container resource usage in the service.

You can configure the container auto scaling rules when creating applications or add the container auto scaling rules for existing applications by changing application configurations.

Auto scaling policies:

  • When the monitoring metric value exceeds the configured upper limit, Container Service increases the number of containers at your configured step.
  • When the monitoring metric value is lower than the configured lower limit, Container Service reduces the number of containers at your configured step.

Service monitoring metrics:

  • Average CPU usage
  • Average memory usage
  • Average outbound/inbound rate

Prerequisites

  • Upgrade the cluster Agent to the latest version. For more information, see Upgrade Agent.

  • Upgrade the cluster monitoring service (acsmonitoring) to the latest version. For more information, see Upgrade system services.

  • Activate the Resource Access Management (RAM) service and update the RAM authorization information in the cluster by completing the following steps:

    1. Log on to the Container Service console.
    2. Click Clusters in the left-side navigation pane.
    3. Click More at the right of the cluster.
    4. Select Update RAM Authorization Information from the list.

Instructions

  • When determining whether the monitoring metric value exceeds the configured upper limit or lower limit, Container Service uses the average value of the monitoring metrics (namely, the average CPU usage and the average memory usage) within a sample period (one minute). Container Service triggers scaling only when the average monitoring metrics of three consecutive sample periods all exceed the configured upper limit or lower limit so as to avoid frequent scaling caused by monitoring data jitter.

  • During container contraction, the system deletes the containers in the cluster. Therefore, back up the data in advance.

Set container auto scaling

Create an application by using an image

  1. Click Create with Image when creating an application.

    For how to create an application, see Create an application.

    1

  2. In the Scaling section at the bottom of the page, select the Enable check box for Auto Scaling and set the auto scaling parameters.

    Constraint rules:

    • The range of the Expansion Condition is 50%–100%. The range of the Contraction Condition is 0%–50%.
    • The Expansion Condition must be at least 30% higher than the Contraction Condition.
    • The range of the Step is 1–5. The default value is 1.
    • Set the Min Number of Containers and Max Number of Containers. For contraction, if the number of containers is less than or equal to the Min Number of Containers, contraction is not performed. For expansion, if the number of containers is greater than or equal to the Max Number of Containers, expansion is not performed.

    Note: Set the scaling policies with due care. If the application already meets the configured scaling conditions when you set the scaling rules and the application still meets the scaling conditions after the scaling, the monitoring will continuously trigger the scaling.

    1

Create an application by using an orchestration template

  1. Click Create with Orchestration Template when creating an application.

    For how to create an application, see Create an application.

    1

  2. Click Use Existing Orchestration Template or write your own orchestration template.

  3. Add the configurations of the container auto scaling by:

    • Clicking Add Service.

      1

      In the displayed dialog box, select the image and configure the corresponding parameters. Click More Settings. Select the Enable check box for Auto Scaling and set the auto scaling parameters.

    • Manually configuring in the template.

      In the labels configurations of the orchestration template, add the corresponding labels:

      • Specify the step (the default value is 1): aliyun.auto_scaling.step
      • Specify the minimum number of containers (the default value is 1): aliyun.auto_scaling.min_instances
      • Specify the maximum number of containers (the default value is 10): aliyun.auto_scaling.max_instances
      • CPU usage as the metric
        • Specify the upper limit: aliyun.auto_scaling.max_cpu
        • Specify the lower limit: aliyun.auto_scaling.min_cpu
      • Memory usage as the metric
        • Specify the upper limit: aliyun.auto_scaling.max_memory
        • Specify the lower limit: aliyun.auto_scaling.min_memory
      • Outbound rate as the metric
        • Specify the upper limit: aliyun.auto_scaling.max_internetOutRate
        • Specify the lower limit: aliyun.auto.scaling.min_internetOutRate
      • Inbound rate as the metric
        • Specify the upper limit: aliyun.auto_scaling.max_internetInRate
        • Specify the lower limit: aliyun.auto_scaling.min_internetInRate

      Compose V1/V2 sample:

      1. web:
      2. image: registry.aliyuncs.com/acs-sample/wordpress:4.5
      3. ports:
      4. - '80'
      5. restart: always
      6. labels:
      7. aliyun.logs: /var/log
      8. aliyun.probe.url: http://container/license.txt
      9. aliyun.probe.initial_delay_seconds: '10'
      10. aliyun.routing.port_80: http://wordpress
      11. aliyun.scale: '3'
      12. aliyun.auto_scaling.max_cpu: '70'
      13. aliyun.auto_scaling.min_cpu: '40'
      14. aliyun.auto_scaling.step: '1'

      Compose V3 sample:

      1. version: '3'
      2. services:
      3. web:
      4. image: wordpress:4
      5. ports:
      6. - 80
      7. deploy:
      8. replicas: 3
      9. restart_policy:
      10. condition: on-failure
      11. labels:
      12. aliyun.routing.port_80: wordpress
      13. aliyun.auto_scaling.max_cpu: '70'
      14. aliyun.auto_scaling.min_cpu: '40'
      15. aliyun.auto_scaling.step: '1'

Change application configurations

You can add container auto scaling settings by changing the configurations of an existing application.

  1. On the Application List page, click Update at the right of the application you want to add the container auto scaling settings.

    For how to change the application configurations, see Change application configurations.

    1

  2. In the labels configurations in Template, add the corresponding container auto scaling labels.

    Compose V1/V2 sample:

    1. web:
    2. image: registry.aliyuncs.com/acs-sample/wordpress:4.5
    3. ports:
    4. - '80'
    5. restart: always
    6. labels:
    7. aliyun.logs: /var/log
    8. aliyun.probe.url: http://container/license.txt
    9. aliyun.probe.initial_delay_seconds: '10'
    10. aliyun.routing.port_80: http://wordpress
    11. aliyun.scale: '3'
    12. aliyun.auto_scaling.max_cpu: '70'
    13. aliyun.auto_scaling.min_cpu: '40'
    14. aliyun.auto_scaling.step: '1'

    Compose V3 sample:

    1. version: '3'
    2. services:
    3. web:
    4. image: wordpress:4
    5. ports:
    6. - 80
    7. deploy:
    8. replicas: 3
    9. restart_policy:
    10. condition: on-failure
    11. labels:
    12. aliyun.routing.port_80: wordpress
    13. aliyun.auto_scaling.max_cpu: '70'
    14. aliyun.auto_scaling.min_cpu: '40'
    15. aliyun.auto_scaling.step: '1'

View created container scaling rules

You can view the created container scaling rules.

  1. Log on to the Container Service console.

  2. Click Applications in the left-side navigation pane.

  3. On the Application List page, click Update at the right of the application.

    You can view the created container scaling rules. You can modify the container scaling rules in the Template.

    1

View monitoring metrics

  1. Click Applications in the left-side navigation pane.

  2. Click the application name on the Application List page.

  3. Click the Containers tab. Click Monitor at the right of the container.

    1

    You can view the monitoring information of this container.

    Note: If the monitoring data does not exist, check:

    • Whether or not the monitoring service (acsmonitoring) is correctly installed (whether or not the status and number of containers are correct). If not, redeploy the monitoring service (acsmonitoring).
    • Whether or not the cluster Agent is in the latest version. If not, upgrade the cluster Agent.
    • Whether or not the monitoring service (acsmonitoring) is in the latest version. If not, upgrade the monitoring service (acsmonitoring).

    1

  4. Log on to the CloudMonitor console to view the container monitoring information.

  5. Click Cloud Service Monitoring > Container Service in the left-side navigation pane.

  6. Click View All Rules on the Clusters page to view the alarm rules automatically configured by auto scaling.

    1

    Note: If no monitoring alarm rules are displayed, update the RAM authorization information in the cluster by completing the following steps:

    1. Log on to the Container Service console.

    2. Click Clusters in the left-side navigation pane.

    3. Click More at the right of the cluster.

    4. Select Update RAM Authorization Information from the list.

      Activate the RAM service before updating the RAM authorization information. Otherwise, the system reports an error.

    3

  7. Select an alarm rule to modify the alarm conditions and notification contacts who can be notified in SMSs, emails, and other ways. You can also disable the alarm rule.

Thank you! We've received your feedback.