What is Persistent Storage?
Persistent storage is a data storage system where data is retained, even when the storage is restarted, the connection is lost, or the container is updated. This type of storage is crucial for saving critical data that must be preserved over long periods, such as user documents, application data, and system settings.
Content
- Why Should You Use It?
- Underlying Technology
- Step-by-Step Guide
- Troubleshooting & FAQs
- Best Practices & Optimization
- References & Additional Resources
Why Should You Use It?
Alternatives
Ephemeral Storage
Each container is allocated 10GB of ephemeral storage by default. This storage is temporary and is cleared when the process is terminated or a device is powered off, for example when the container is updated (e.g., a new version). Ephemeral thus means "short-lived."
Session Storage
In web applications, session storage is used to store data related to the user’s session. The data is stored in memory and is cleared when the session ends.
RAM (Random Access Memory)
RAM is a form of volatile memory that is used for temporary data storage and is lost when the device is powered off. It’s usually used for active processes and data that needs to be accessed quickly.
Use Cases
Persistent storage can be especially useful if you want to retain the data from your application. As mentioned earlier, all data in ephemeral storage is lost, unlike persistent storage. Below are some situations where you would prefer to use persistent storage:
- You want to always be able to view your application logs.
- You want to keep important data and not lose it after an update.
- Persistent storage can also function as a backup.
- If you periodically extract data from your application and want to retain it.
- If you want to preserve the state of data, such as for message queues, so the message is not lost during a restart
Underlying Technology
The persistent storage is NFS storage. This means that you can read from and write to the storage. However, you need to be careful because if you delete something, it cannot be recovered. Also, if you write to a file that already exists, the file will be replaced with the new one, and the old one will be lost.
Step-by-Step Guide
Setting up a persistent storage
Go to the tab 'Volumes'.
Click on the button 'Add Volume+'.
Fill in the name and size of the volume.
Click on 'Add Volume'.
Go to the container that you want to assign the volume to.
Go to the tab 'Configure'.
Enable 'Add persistent storage to your container'.
Click on 'Mount Existing Volume', you can also create a new volume here if you didn't create one yet.
Select the volume you created in steps 3 and 4, and fill in the path where you want the persistent storage to be located.
Click on 'Add'.
Click on 'Apply' to apply the changes you have made.
The persistent storage is now being assigned to the container.
Toubleshooting & FAQs
My app is not working anymore after setting up the persistent storage (directory or file not found)?
If you choose an existing folder as the path for your persistent storage, that folder will be replaced by a new one, and the files inside will be deleted. For example, if you choose /app (where your application is located, the workdir), your files will be replaced and deleted, and your application will no longer exist, causing the container to crash. If you change the path afterward to an empty folder, the old app folder will be restored.
What happens when I delete a container with persistent storage?
The storage is linked to a volume, and as long as the volume exists, the data within it will be preserved. Even if the container to which the storage is attached is removed, the data remains. And the volume will still exist.
How do I decrease the size of the persistent storage?
You can’t. You can only increase the persistent storage, not decrease it. This is to prevent potential data loss.
What is the lost+found folder?
The lost+found folder in Linux and Unix systems serves a specific purpose related to filesystem integrity and file recovery. This directory is used by the filesystem check utility (fsck), to recover files that have been orphaned due to filesystem corruption or damage. When such issues occur, fsck attempts to salvage files that would otherwise be lost and places them in the lost+found directory, linking them by their inode numbers rather than their original filenames.
Best Practices & Optimization
Recommendations
- You can add a volume to multiple container. So, it's recommended to use one volume per namespace.
- Make the path to your persistent storage logically. Don't fill in some random names.
Scalability
You can only increase the persistent storage, not decrease it. This is to prevent potential data loss. When you increase the storage, it take effect immediately. And in contrast to the container you can't auto-scale the volumes
References & Additional Resources
Comments
Please sign in to leave a comment.