How to Use Droplet Autoscale Pools for Automatic Horizontal Scaling

DigitalOcean Droplets are Linux-based virtual machines (VMs) that run on top of virtualized hardware. Each Droplet you create is a new server you can use, either standalone or as part of a larger, cloud-based infrastructure.


Droplet autoscale pools enable automatic horizontal scaling for a pool of Droplets based on resource utilization or a fixed size.

Create an Autoscale Pool with the Control Panel

When you create an autoscale pool, you define the scaling configuration for the pool as well as the configuration for Droplets in the pool.

From the DigitalOcean Control Panel, in the left menu, click Droplets, which has both a Droplets tab and an Autoscale Pools tab.

The autoscale pools tab in the control panel with one autoscale pool listed.

Click the Create an Autoscale Pool button to go to the autoscale pool creation page

Autoscale Pool Configuration

In the Autoscale Pool Configuration section, you choose the configuration of the pool:

  • Autoscale dynamically manages the number of Droplets in the pool based on their aggregate resource utilization. You choose:

    • Pool Size, which controls the minimum and maximum number of Droplets in the pool.

    • Target Utilization, which control which metrics (CPU, memory, or both) to monitor and at what thresholds to scale.

      Autoscale pools set to autoscale determine how many Droplets the pool should have by multiplying the utilization ratio by the current number of Droplets in the pool and taking the ceiling of the result. With multiple metrics set, the pool uses the largest result of this calculation across all metrics.

      For example, an autoscale pool with 2 Droplets, a target utilization of 80% CPU, and a current utilization of 95% CPU would scale to 3 Droplets: ceil(2 Droplets * (80% target CPU / 95% current CPU)) = ceil(2.375) = 3.

    • Cooldown Duration, which is the minimum amount of time the autoscale pool waits between making modifications to the Droplets in the pool. This cooldown prevents thrashing during scaling and prevents downtime during configuration changes by giving new Droplets time to boot before destroying the old ones.

      Choose a cooldown duration at least as long as it takes your Droplets to boot.

  • Fixed Size maintains a fixed number of Droplets in the pool. Autoscale pools set to fixed size have a cooldown duration of 10 minutes which you cannot change. You choose:

    • Number of Droplets. The quantity of Droplets you want in the pool.

Autoscale Pool Droplets Configuration

In the Autoscale Pool Droplets Configuration section, choose the configuration for Droplets within the autoscale pool:

  • Datacenter region

  • VPC network

  • Image, which can be a base OS image, a snapshot or backup, or a custom image.

  • Droplet plan

  • SSH keys, which are mandatory

  • IPv6

  • Startup scripts, which is user data

Make sure that Droplets in the pool automatically run your application on boot to make the application available on Droplets that the autoscale pool provisions. For example, you can configure unit files in a custom image or specify user data.

Finalize

In the Finalize section, you choose following options:

  • A unique autoscale pool name

  • A project for the autoscale pool

  • Optionally, tags for the Droplets in the pool

We strongly recommend tagging the Droplets in your autoscale pool. This lets you use DigitalOcean Load Balancers to forward traffic to the entire pool and apply cloud firewall rules to the pool automatically.

When you finish selecting your configuration, click Create Autoscale Pool.

Edit or Destroy an Autoscale Pool

You can access and perform actions on Droplets in an autoscale pool like regular Droplets, but we strongly recommend not modifying or adding resources to Droplets in an autoscale pool. These changes do not propagate to new or other existing Droplets in the pool and are lost if the autoscaling pool deletes the Droplet. Instead, change the Droplet configuration for the autoscaling pool.

With the Control Panel

To view or edit an autoscale pool from the DigitalOcean Control Panel, in the left menu, click Droplets, then click the Autoscale Pools tab to go to the autoscale pools page. This page lists your team’s autoscale pools with an overview of their status. Click on an autoscale pool to go to its detail page:

The resources tab of an autoscale pool.

Each autoscale pool page has the following tabs:

  • The Resources tab displays information about the pool, like the individual Droplets, the average resource utilization, and the pool size.

  • The Insights tab displays graphs for the number of Droplets in the pool and average resource utilization.

  • The Activity tab displays a history of events in the pool, like configuration changes and provisioning.

  • The Settings tab displays both the autoscale pool configuration and the Droplet configuration.

The Settings tab is where you can modify or destroy the pool.

The settings tab of an autoscale pool.

To edit the pool, click Edit next to the setting you want to change. You can change the Droplet configuration for the pool, switch between autoscale and fixed size, and modify the pool configuration.

When you change the Droplet configuration, the autoscale pool provisions Droplets with the new configuration, then waits for the cooldown duration before destroying the old Droplets. During this time, the pool temporarily has twice as many Droplets and may exceed the maximum size of the pool.

The Settings tab is also where you can destroy the pool. In the Destroy Autoscale Pool section, click Destroy. In the window that opens, optionally check Destroy Droplets in the pool to destroy the Droplets in the pool, or leave it unchecked to keep the Droplets after the pool is destroyed. Enter the name of the autoscale pool in the confirmation box, then click Delete. This permanently and irreversibly destroys the autoscale pools and all Droplets in the pool.

Manage Autoscale Pools with Automation

Using the API

How to Create a New Autoscale Pool Using the DigitalOcean API
  1. Create a personal access token and save it for use with the API.

  2. Send a POST request to https://api.digitalocean.com/v2/droplets/autoscale

    cURL

    Using cURL:

                    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{
        "name": "test-autoscalergroup",
        "config": {
          "min_instances": 1,
          "max_instances": 5,
          "target_cpu_utilization": 0.5,
          "cooldown_minutes": 5
        },
        "droplet_template": {
          "size": "c-2",
          "region": "tor1",
          "image": "ubuntu-20-04-x64",
          "tags": [
            "test-ag-01"
          ],
          "ssh_keys": [
            "392594",
            "385255"
          ],
          "vpc_uuid": "c472520a-831e-4770-8135-542c57a69daa",
          "ipv6": true,
          "user_data": "\n#cloud-config\nruncmd:\n- apt-get update\n"
        }
      }' \
      "https://api.digitalocean.com/v2/droplets/autoscale"
                  
How to Update Autoscale Pool Using the DigitalOcean API
  1. Create a personal access token and save it for use with the API.

  2. Send a PUT request to https://api.digitalocean.com/v2/droplets/autoscale/{autoscale_pool_id}

    cURL

    Using cURL:

                    curl -X PUT \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{
        "name": "test-autoscalergroup-01",
        "config": {
          "min_instances": 1,
          "max_instances": 5,
          "target_cpu_utilization": 0.5,
          "cooldown_minutes": 10
        },
        "droplet_template": {
          "size": "c-2",
          "region": "tor1",
          "image": "ubuntu-20-04-x64",
          "tags": [
            "test-ag-01"
          ],
          "ssh_keys": [
            "372862",
            "367582",
            "355790"
          ],
          "vpc_uuid": "4637280e-3842-4661-a628-a6f0392959d3",
          "with_droplet_agent": true,
          "ipv6": true,
          "user_data": "\n#cloud-config\nruncmd:\n- apt-get update\n"
        }
      }' \
      "https://api.digitalocean.com/v2/droplets/autoscale/d0067f19-c9bd-4d8c-b28b-e464fd1fb250"
                  
How to Delete Autoscale Pool Using the DigitalOcean API
  1. Create a personal access token and save it for use with the API.

  2. Send a DELETE request to https://api.digitalocean.com/v2/droplets/autoscale/{autoscale_pool_id}

    cURL

    Using cURL:

                    curl -X DELETE \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      "https://api.digitalocean.com/v2/droplets/autoscale/880fee37-d07a-4f94-94a0-f07d9fc7bbb4"
                  

Using Terraform

Provides a DigitalOcean Droplet Autoscale resource. This can be used to create, modify, read and delete Droplet Autoscale pools.
Get information on a Droplet Autoscale pool for use with other managed resources. This datasource provides all the Droplet Autoscale pool properties as configured on the DigitalOcean account. This is useful if the Droplet Autoscale pool in question is not managed by Terraform, or any of the relevant data would need to referenced in other managed resources.