Setup a Volume
Volumes provide persistent block storage that can be attached to instances for storing data independently of the instance lifecycle. This makes them ideal for scenarios where you need to maintain critical data even after instances are deleted or replaced. Volumes can be reused and mounted across multiple instances, providing flexibility and durability for your storage needs.
In this guide, we will cover how to create a volume, attach it to an instance, and verify that it is mounted via the Shadeform API. This process involves creating a volume first, launching an instance with the volume attached, and confirming the volume on the instance.
Currently, volumes can only be attached to instances in the same cloud provider and region. Multi-cloud volumes are an upcoming feature.
Prerequisites
There are two pre-requisites for this guide:
- After you have created your account, you must top up your wallet here.
- After you have topped up your wallet, generate and retrieve your Shadeform API key here.
Step 1: Check Available Volume Types
To create a volume, you first need to know what volume types are available. Use the /volumes/types
endpoint to fetch this information.
Example Response
The response will list the supported volume types. Here is an example (this is example data and may not have correct values):
Take note of the cloud
and region
fields for the next step.
Step 2: Create a Volume
Now that you know the volume type and region, create the volume using the /volumes/create
API.
Replace <api-key>
with your API key, and customize the cloud
, region
, and size_in_gb
fields to match your requirements.
Example Response
The response will include the id
of the newly created volume, which will be used to attach it to an instance.
Save the id
field as you will need it in the next step.
Step 3: Create an Instance with the Volume Attached
To attach the volume, pass its id
in the volume_ids
field while creating the instance using the /instances/create
endpoint.
Example Response
The response will include the id
for the instance and a cloud_assigned_id
. Save this for further operations.
Step 4: Verify the Volume on the Instance
Once the instance is active, SSH into it to verify that the volume has been mounted. Learn how to SSH into a Shadeform instance using this guide.
After connecting, run the following command:
Your output should look something similar to this:
This command will display all block devices attached to the instance. You should see your volume listed as a new device, such as vdb
, sbd
, or similar.
Step 5: Mount the volume to a file system
After verifying the volume is attached, you can mount it to a file system. Find your volume from the lsblk
command (my volume is called vdb
in this example) and mount it to a directory using the following commands:
Now, the /mnt/vdb
directory should be connected to your volume and fully accessible for you to write and read from.
Step 6: Deleting the Instance and Volume
Before you can delete a volume, you must delete the instance it is attached to.
Delete the Instance
Use the /instances/delete
endpoint to remove the instance.
Replace <instance-id>
with the id
of your instance.
Delete the Volume
Once the instance has been deleted, you can safely delete the volume using the /volumes/delete
endpoint.
Replace <volume-id>
with the id
of the volume.
Summary
You have successfully created a volume, attached it to an instance, verified the attachment, and learned how to clean up resources. For more details, check out the Shadeform API reference.