Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Creating Autoscaling Volumes

Create new EBS volumes and PVCs that autoscale from the moment they're created, with no activation and no initial data copy.

Creating an autoscaling volume gives you a new, empty volume that autoscales from the moment it's created. This is different from activating autoscaling, which applies to an existing volume and starts by copying its data to Datafy Volumes.

Creating the volume as autoscaling, rather than letting an autoscaling rule activate it later, works best for:

  • Short-lived workloads — a volume that exists for only minutes or hours can spend a large share of its life, or all of it, at full size, waiting for activation to complete.

  • Very large volumes — the more data there is to copy, the longer activation takes.

There are a few ways to create an autoscaling volume. Choose the one that matches how the volume is used:

  1. PVCs in Kubernetes — annotate a PVC, or set a StorageClass parameter.

  2. Volumes attached to EC2 instances — create and attach the volume with the Datafy API, or with Terraform and the datafyaws provider.

Volumes attached directly to Kubernetes nodes, rather than claimed by PVCs, are created the same way as volumes attached to EC2 instances.

The exception is a Bottlerocket local volume (Bottlerocket's data volume), which is created when the node launches. Activate autoscaling on it with an autoscaling rule instead. See Bottlerocket Local Volumes.

Volume Creation Parameters

These parameters apply to every volume created as autoscaling, whatever the method:

  • Size — the size you request is the volume's maximum size, and the size the filesystem sees. It must be at least your account's Autoscaling Minimum Size. The volume starts at about the Autoscaling Minimum Size (by default, 50 GiB or 10% of the requested size, whichever is larger), and grows up to the requested size as data is written.

  • Volume type — gp3 only.

  • IOPS and throughput — 3,000 IOPS and 125 MiB/s by default. You can set 3,000–16,000 IOPS and 125–1,000 MiB/s, with up to 1 MiB/s of throughput for every 4 IOPS.

  • Encryption — volumes are encrypted by default, with your AWS account's default EBS encryption key. You can set a custom KMS key instead.

  • Tags — tags you set when creating the volume are added to its Datafy Volumes in AWS, and appear on the volume in the Datafy app.

  • Volume ID — Datafy returns an ID that identifies the autoscaling volume in the Datafy app and the Datafy API. In Kubernetes, the PersistentVolume bound to the PVC references this ID. It's a virtual ID that doesn't appear in the AWS console. The Datafy Volumes that hold the data carry the tag datafy:source-volume:id with this ID.

This is similar to creating an autoscaling volume from a Datafy snapshot, except that the new volume is empty.

PVCs in Kubernetes

Create a new autoscaling volume in one of two ways:

Annotating a PVC

Add the datafy.io/autoscaling-native: "true" annotation to new PVCs:

For consistent sizing, set PVC sizes in binary units (Gi) rather than decimal units (G).

The annotation only takes effect before the volume is provisioned:

  • The value must be "true" or "false". Only "true" creates an autoscaling volume.

  • You can add, change, or remove the annotation while the PVC is unbound. With a WaitForFirstConsumer StorageClass, that's until a pod using the PVC is scheduled.

  • Once the PVC is bound to a PersistentVolume, the annotation can't be added. To autoscale a volume that already exists, activate autoscaling on it instead.

  • Datafy removes the annotation from the PVC when the volume is first attached to a node, and it continues as an autoscaling volume.

Setting a StorageClass Parameter

To make every new PVC of a StorageClass autoscale, add datafy.io/autoscaling-native: "true" to the StorageClass parameters:

When the StorageClass sets the parameter, it applies to every PVC of that class, and the PVC annotation is ignored. Setting the parameter to "false" stops PVCs of that class from autoscaling at creation, even if they're annotated.

StorageClass Parameters That Apply

Of the EBS CSI driver's StorageClass parameters, these apply to autoscaling PVCs:

  • iops and throughput — within the limits in Volume Creation Parameters. iopsPerGB isn't applied, so set iops explicitly for more than the default 3,000 IOPS.

  • tagSpecification_<n> — applied as described in Volume Creation Parameters.

  • csi.storage.k8s.io/fstype — ext4 or xfs. The CSI driver formats the volume on first mount, as for any PVC.

Autoscaling PVCs are always gp3, whatever type the StorageClass sets.

If Datafy rejects the request, for example because it's below the minimum size, the PVC stays Pending with a ProvisioningFailed event.

A PVC restored from a Datafy snapshot is always created as an autoscaling volume, with or without the annotation.

Volumes Attached to EC2 Instances

Creating an autoscaling volume for an EC2 instance follows the same flow as creating an EBS volume through AWS. Only the create and attach steps are different: you run them with the Datafy API instead of the EC2 API, or with Terraform using the datafyaws provider. Everything after the attach, such as formatting and mounting, is the same as for any new EBS volume.

Step
AWS
Datafy API
Terraform

Create the volume

aws_ebs_volume with provider = datafyaws and datafy_autoscaling = true

Attach it to an instance

aws_volume_attachment with provider = datafyaws

Using the Datafy API

  1. Create the volume with the create-autoscaling-volume endpoint. Pass the instance's Availability Zone and the size in GiB, plus any other volume creation parameters. The response includes the new volume ID.

  2. Attach the volume with the attach endpoint. Pass the instance ID and a device name that isn't in use on the instance, such as /dev/sdf. AutoScaler doesn't need to be installed on the instance yet.

  3. Once AutoScaler is installed on the instance, format and mount the volume as you would any other EBS volume. Until then, the volume can't be used in any way, including formatting and mounting.

On the instance, the volume appears as /dev/dvol<ID>, where <ID> is the volume ID without the vol- prefix. For example, vol-0a1b2c3d4e5f67890 appears as /dev/dvol0a1b2c3d4e5f67890. You can format and mount it using either this path or the device name you passed when attaching it, such as /dev/sdf.

The device can take a few minutes to appear after the volume is attached.

Using Terraform

Before you start, set up the datafyaws provider. See IaC Reconciliation.

Instead of the API calls in steps 1 and 2, set datafy_autoscaling = true on an aws_ebs_volume resource, and attach it with aws_volume_attachment, both using the datafyaws provider:

  • Set type = "gp3". The plan fails if type is unset or set to any other type.

  • size, iops, throughput, encrypted, kms_key_id, and tags apply as described in Volume Creation Parameters. size is the volume's maximum size.

  • datafy_autoscaling can't be added to or changed on an existing volume. To autoscale a volume that already exists, activate autoscaling on it instead.

  • To remove datafy_autoscaling from the configuration, deactivate autoscaling on the volume first, then delete the argument. Setting it to false isn't allowed.

  • To change size, iops, or throughput later, see Modifying Autoscaling Volumes.

After terraform apply, format and mount the volume as in step 3 of Using the Datafy API.

Automating Volume Creation at Launch

You can use the Datafy API calls as part of your automated instance provisioning, for example in the instance's user data.

Example: Creating a Volume From User Data

This example runs the whole flow from an instance's user data, so the instance boots with a new autoscaling volume. It installs AutoScaler, then creates, attaches, formats, and mounts a 200 GiB xfs volume at /data. Adapt it to your environment:

  • It's written for Amazon Linux 2023.

  • Replace <VERSION> with the AutoScaler version to install, and <YOUR_TOKEN> with your API token.

By default, EC2 runs user data scripts only on an instance's first boot, so the script creates one volume per instance. On later boots, the /etc/fstab entry mounts the same volume.

Last updated

Was this helpful?