How to configure CPU-based autoscaling on DigitalOcean
DigitalOcean's CPU-based autoscaling automatically adjusts the number of droplets based on CPU usage metrics. You configure it by creating a droplet group, setting CPU thresholds (typically 70% for scaling up, 30% for scaling down), and defining minimum/maximum instance limits.
Prerequisites
- Active DigitalOcean account
- Load balancer configured in your project
- Droplet image or snapshot prepared for scaling
- Basic understanding of server monitoring and scaling concepts
Step-by-Step Instructions
Create a Load Balancer
/ or your application's health endpoint. This load balancer will distribute traffic across your auto-scaled droplets.Prepare Your Droplet Template
app-v1.2-template.Access Kubernetes or App Platform
Configure the Autoscaling Group
Set CPU Thresholds and Policies
Configure Monitoring and Alerts
Test the Autoscaling Configuration
ab -n 10000 -c 100 http://your-load-balancer-ip/ or wrk -t12 -c400 -d30s http://your-load-balancer-ip/ to simulate traffic. Monitor the Metrics tab to watch CPU utilization and scaling events. Verify that new droplets are added to the load balancer automatically and removed when load decreases.Optimize and Fine-tune Settings
Common Issues & Troubleshooting
Autoscaling is not triggering despite high CPU usage
Check that your monitoring agent is installed and running on all droplets. Verify that the CPU metric is being reported correctly in the Metrics dashboard. Ensure your scaling policies have the correct thresholds and that the evaluation period isn't too long.
New droplets are created but not receiving traffic
Verify that new droplets are being automatically added to your load balancer. Check the health checks configuration - failing health checks prevent traffic routing. Ensure your application starts correctly on boot and responds to the health check endpoint within the timeout period.
Frequent scaling up and down (thrashing)
Increase the cooldown period between scaling events to at least 5-10 minutes. Widen the gap between scale-up and scale-down thresholds (e.g., 75% up, 25% down). Review your application's CPU usage patterns and consider using a longer evaluation period for scaling decisions.
Costs are higher than expected due to scaling
Set appropriate maximum limits on your node pools and enable cost monitoring alerts. Review your scaling thresholds - they might be too aggressive. Consider using smaller droplet sizes or implementing time-based scaling policies to reduce instances during low-traffic periods. Monitor your usage patterns and adjust policies accordingly.