How to create replicas of running droplets for scheduled time? After schedule time droplets replicas should be remove.
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hey!
This is not available out of the box via the DigitalOcean UI, but you can achieve this using different tools like Terraform, doctl or even only the DigitalOcean API itself.
Here is an example on how to do this with Terraform:
Prerequisites
Steps
1. Install and Configure Terraform
Install Terraform:
brew install terraform
Create a Terraform Configuration File:
Create a Variables File (
variables.tfvars
):Initialize and Apply Terraform Configuration:
2. Schedule Creation and Deletion of Droplet Replicas
Create a Shell Script for Terraform Apply (
create_replicas.sh
):Create a Shell Script for Terraform Destroy (
destroy_replicas.sh
):Schedule the Scripts Using cron:
Open the crontab editor:
Add the following lines to schedule the creation and deletion of droplets:
An alternative approach would be to just use the doctl CLI:
Prerequisites
doctl
on your local machine.Installation
Install
doctl
:brew install doctl
doctl
GitHub releases page and add it to your PATH.Authenticate
doctl
:Steps
1. Create a Script to Create Droplet Replicas
Create a Shell Script for Creating Droplets (
create_replicas.sh
):Make the Script Executable:
2. Create a Script to Delete Droplet Replicas
Create a Shell Script for Deleting Droplets (
destroy_replicas.sh
):Make the Script Executable:
3. Schedule the Scripts Using cron
Open the crontab editor:
Add the following lines to schedule the creation and deletion of droplets:
Feel free to share more details on the exact goal that you want to achieve and I will be happy to advise you furhter.
Best,
Bobby
Heya, @sorcfllow
Another thing to mention is that you can use the DigitalOcean API after the droplet is removed to clear the snapshots as well.
You can check this article on how to set this:
https://docs.digitalocean.com/products/snapshots/how-to/delete/
Regards
Heya,
You can utilize
doctl
. Here’s a step-by-step guide to setting this up:1. Installing
doctl
:First, ensure you have
doctl
installed. If not, you can install it by following the instructions on the DigitalOcean documentation page.2. Authenticating
doctl
:Once installed, you need to authenticate
doctl
with your DigitalOcean account using an API token:You will be prompted to enter your DigitalOcean API token.
3. Creating a Snapshot of the Droplet:
Before creating a replica, you need a snapshot of the Droplet. This can be automated using
doctl
. Here’s how you can create a snapshot:Replace
<droplet-id>
with your Droplet’s ID and"snapshot-name"
with the desired name of your snapshot.4. Creating a Replica Droplet from the Snapshot:
Once the snapshot is created, you can create new Droplets based on this snapshot:
Modify
"replica-droplet-name"
,"s-1vcpu-2gb"
,"snapshot-name"
, and"nyc1"
according to your requirements.5. Scheduling the Creation and Deletion:
To automate the creation and deletion of the replicas at scheduled times, you can use
cron
on Linux or Task Scheduler on Windows.Example of a
cron
job:manage_droplets.sh
):crontab
:This example schedules the script to run daily at 4:00 AM.