Learning paths / Deploy on ComputeSphere / Data: databases and storage

SphereStor volumes: create, mount, unmount

Reading · 5 min · Module 5, lesson 2 of 541 min left in this module

Module 5 · Data: databases and storageLesson 2 of 5

Goal: Create a SphereStor volume and mount it at a path on a service.

3:39 · captions and chapters · narrated with an AI-generated voice
Transcript

Narration uses an AI-generated voice.

[00:00] Where we're going

By the end of this video, you'll give a service a disk that outlives its spherelet. And we'll prove it, with a restart.

[00:08] The problem

Here's the notes app. It keeps one note, in a file under slash data. Let's save a note, and read it back. There it is. Before restart.

Now, in the console, choose Restart, and Restart again in the dialog. A restart replaces the spherelet. Watch its name here change, once the new one is healthy.

Let's read the note again. Nothing. The file was on the old spherelet's own filesystem, and that went away with it.

[00:39] What a volume is

A SphereStor volume fixes that. It's a disk that lives in the environment, not in the spherelet. You mount it on a service at a path, like slash data. Your app just sees a folder. When the spherelet is replaced, the new one gets the same volume. And your files are still there.

You set it up in three steps, in order. First, quota. That's the storage your account pays for, at twenty five cents per GB per month. Second, a volume, carved out of that quota. Third, a mount, which attaches the volume to a service. SphereStor comes with the Pro, Team and Enterprise plans. This account already has quota, so let's start with the volume.

[01:25] Create a volume

Open the environment, and choose the Storage tab. Then New SphereStor volume. Name it notes-data, and give it one GB. Choose Create. And there it is. One GB, and no services using it yet.

[01:41] Mount it

Now open the service's settings, and find the Storage card. Choose Configure storage. Pick the volume, and enter the mount path, slash data. That's exactly where the app writes. Then Save.

The card says Unmounted. Saving doesn't attach it yet. So choose Mount, then Mount again in the dialog. The status turns Mounted, and the service restarts on a new spherelet, with the volume attached.

[02:11] Prove it

Let's run the same test. Save a note, and read it back. Saved on the volume.

Now Restart again, and wait for the new spherelet. There it is. A different name, so a fresh spherelet.

Read the note one more time. It's still there. It lives on the volume, not on the spherelet.

[02:34] Limits to design around

One limit to design around. A volume attaches to one spherelet at a time. So keep the service at one spherelet. Extra ones, including ones autoscaling adds, can't see the data. If several spherelets or services need the same data, it belongs in a database or object storage.

And a mounted volume can't be deleted. From its menu, choose Delete, and type its name. The console refuses: remove SphereStor from all services before deleting. So unmount it first. Then delete destroys the data for good.

[03:12] Recap and your lab

So, a quick recap. Quota, then a volume, then a mount. Save, then Mount. Your app must write under the mount path. And a volume survives restarts, but it's not a backup. Now it's your turn. In the lab, you'll mount a volume on your own notes app, and prove the note survives. I'll see you there.

Key idea

A SphereStor volume is a disk that lives in an environment. You mount it on a service, which makes it appear as a folder such as /data, and whatever your app writes there survives when the spherelet is replaced.

Three pieces, three places

You set up storage in order: quota on your account, a volume in the environment, a mount on the service. SphereStor comes with the Pro, Team and Enterprise plans; Hobby doesn't include it.

  • Quota is the total storage you've paid for, in GB, at $0.25 per GB per month. You pay for it whether or not your volumes use it all.
  • A volume is a named disk carved out of that quota. It can't be bigger than the quota you have left.
  • A mount attaches the volume to a service at a path.

1. Add quota

Open the environment and choose the Storage tab, then Manage quota (or Add SphereStor quota if it says No SphereStor quota). On your account's SphereStor tab, choose Add storage and set the GB you need. 1 GB is plenty for this module's lab.

2. Create a volume

Back on the environment's Storage tab:

  1. Choose New SphereStor volume.
  2. Enter a Volume name, for example notes-data, and a Storage size (GB).
  3. Choose Create.

The list shows each volume with its size and how many services use it. It's ready to mount a few seconds later.

3. Mount it on a service

  1. Open the service, then Settings, then the Storage card.
  2. Choose Configure storage.
  3. Under SphereStor volume, pick your volume.
  4. Enter the Mount path, for example /data. It must start with /.
  5. Choose Save. The card shows the volume as Unmounted.
  6. Choose Mount, then Mount again in the dialog.

The status turns Mounted, and the service restarts on a new spherelet with the volume attached.

Your app must write to that exact path. If it writes to /app/data and you mounted /data, the files still land on the temporary filesystem.

Limits to design around

A volume attaches to one spherelet at a time:

  • Keep the service at 1 spherelet. Extra spherelets, including ones autoscaling adds, can't see the data.
  • One service per volume, and in the console one volume per service.
  • Mount a folder your app owns, not one your image already fills (like /app). The volume hides what was at that path.

If several spherelets or services need the same data, it belongs in a database or object storage (lesson 5.5.1).

Unmount, resize and delete
  • Unmount (on the service's Storage card) disconnects the volume and restarts the service without it. The data stays on the volume: choose Configure storage and mount it again to get it back.
  • Resize with Edit in the volume's menu on the environment's Storage tab. Volumes can grow but not shrink.
  • Delete from the same menu destroys the data and can't be undone. Unmount the volume first; a mounted volume can't be deleted.

Volumes are managed in the console and the API; csph has no volume commands yet. A mounted service's Storage card also has Open SphereFiles, a file browser for checking what your app wrote.

Check yourself

You mounted a volume at /data, but your app saves files to /app/storage. What happens on the next redeploy?

In the docs