Question

Cron-based droplet management (provisioning and destroying) of droplets

Hey everyone,

I’m new to DigitalOcean and exploring ways to optimise costs, especially during off-hours. I’d love to learn how you handle automating tasks like shutting down droplets that aren’t in use.

  • How are you currently automating droplet or cluster shutdowns for cost optimisation? For example, managing Dev/Test workloads, weekly batch processing, etc.

  • I’m fairly technical (though new to DO) and can think of using scripts with the DO APIs to handle this, but managing multiple droplets could get pretty unwieldy.

Lastly, are there any add-ons or tools in the DO Marketplace that you’d recommend for this kind of use case?

Looking forward to your insights—thanks in advance!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
January 8, 2025
Accepted Answer

Hey Sudarshan! 👋

Welcome to DigitalOcean! Automating droplet management is a smart way to optimize costs, especially for non-production workloads like Dev/Test environments.

There are a few ways to do this:

1. Using the DigitalOcean API and doctl:

The DigitalOcean API provides endpoints for managing Droplets, such as creating, powering off, or deleting them. You can use this with a cron job or scheduler to automate the process. For example:

  • Shutdown a Droplet:

    doctl compute droplet-action power-off DROPLET_ID
    
  • Start a Droplet:

    doctl compute droplet-action power-on DROPLET_ID
    
  • Delete a Droplet:

    doctl compute droplet delete DROPLET_ID
    

It’s important to note that even if a Droplet is powered off, you will still be charged for the allocated resources. To stop incurring charges, you need to delete the Droplet. You can always use a snapshot before deletion to preserve the state of your Droplet.

2. Consider Kubernetes for Auto-Scaling:

If your workload can be containerized, Kubernetes can be a great alternative for managing resources dynamically. DigitalOcean Kubernetes supports auto-scaling, allowing you to scale up and down based on resource demands automatically. Check out this guide for more details: 👉 How to Enable Auto-Scaling in DigitalOcean Kubernetes

3. Explore Serverless Functions:

For even more cost optimization, you could consider moving certain workloads to DigitalOcean Functions:

👉 https://docs.digitalocean.com/products/functions/


Hope that this helps and let me know if you have any questions!

- Bobby

alexdo
Site Moderator
Site Moderator badge
January 10, 2025

Heya, @sudarshan89

On top of what’s already been mentioned. You can leverage DigitalOcean’s monitoring service to track resource utilization in real-time. Pair this with automation to dynamically scale resources:

  • Set CPU/Memory thresholds.
  • Trigger scripts or webhook-based alerts when thresholds are crossed.
  • Integrate with tools like Prometheus or Grafana for deeper insights.

In order to avoid being charged for idle droplets, automate snapshot creation and droplet deletion:

  • Take snapshots periodically to preserve the droplet’s state:
doctl compute droplet-action snapshot DROPLET_ID --snapshot-name "snapshot-$(date +%Y%m%d)"
  • Delete the droplet after snapshot creation:
doctl compute droplet delete DROPLET_ID
  • Restore the droplet from snapshots when needed:
doctl compute droplet create --image SNAPSHOT_ID

Also If you have predictable workload cycles, use job schedulers like cron or orchestration tools like Ansible to automate provisioning:

  • Provision additional resources during peak usage times.
  • Scale down or shut off droplets during weekends, nights, or holidays.

Hope that this helps!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.