You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Terraform搭建VPS集群后,如何实现垂直扩容?

Vertical Scaling Your DigitalOcean Droplet Cluster with Terraform

Hey there! Glad to hear your Terraform-managed VPS cluster is running smoothly. Let's break down how to perform vertical scaling (upgrading the instance size) for your 3 DigitalOcean Droplets.

Step 1: Update the Instance Size Configuration

You've defined the swarm_instance_size variable to control your Droplet size, so we'll start here. You have two flexible options to adjust this:

Option 1: Modify the Variable's Default Value

Edit your Terraform variable definition to set the new desired size (e.g., 2gb, 4gb, or any valid DigitalOcean instance size):

variable "swarm_instance_size" {
  default = "2gb" # Replace with your target instance size
}

Option 2: Pass the New Size via Command Line (No Code Change)

If you prefer not to modify your code (for example, a one-off scaling test), use the -var flag when running terraform apply:

terraform apply -var "swarm_instance_size=2gb"

Step 2: Preview the Change (Always Do This First!)

Before making any live changes, run terraform plan to verify exactly what Terraform will do:

terraform plan

You should see output indicating that all 3 digitalocean_droplet.server resources will be updated in-place. This is critical—it means Terraform will resize your existing Droplets instead of destroying and recreating them, so your data and setup stay intact.

Important: While DigitalOcean's resize operation is generally safe, it's smart to take snapshots of your Droplets before scaling, just as a precaution.

Step 3: Execute the Scaling

Once you're comfortable with the plan, run the apply command to trigger the resize:

terraform apply

Confirm the change when prompted, and Terraform will handle resizing all 3 Droplets to the new size. Keep in mind your Droplets may restart during this process, so schedule this during a maintenance window if your application can't tolerate brief downtime.

Key Notes to Keep in Mind

  • Region Availability: Ensure your target instance size is available in the sfc1 region you're using. Some sizes are region-specific, so double-check compatibility first.
  • Billing: Resizing will adjust your billing rate to match the new instance size—review DigitalOcean's pricing for your target size beforehand.
  • Partial Scaling: If you only want to resize a subset of Droplets, you'll need to split your resource definition. For example, create a separate digitalocean_droplet block using for_each instead of count to specify individual sizes for different instances.

内容的提问来源于stack exchange,提问作者Snowball

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:01:23