Launching a persistent database service

Launching a persistent database to levv cloud #

Persistent databases are designed to store information on non-volatile media, such as disk storage, ensuring that the information remains even in the event of a system shutdown or failure. Common examples of persistent databases are MySQL and PostgreSQL.

This guide demonstrates how to create persistent media using Volumes on levv cloud and how to make use of it in a database service.

1. Creating a Volume #

Volumes are scoped by Project and can be created using the levv CLI:

levv volumes create

The cli will then request the name, size (in GB), and the project name where the volume will be created.

Alternatively you can provide all arguments directly:

levv volumes create --size 1 --project my-project db-volume

In any case a confirmation dialog will be displayed before proceeding with the creation.

2. Mounting the Volume in the service #

Once the Volume has been created it can be mounted in the appropiate service.

In this example we will use MySQL to create a database service.

# database.yml
services:
    database:
        image: mysql
        environment:
            MYSQL_ROOT_PASSWORD: example # This is just an example, not intended for real use cases
        volumes:
            - db-volume:/var/lib/mysql
        labels:
            io.levv.size: nano
volumes:
    db-volume:

In this configuration, note that volumes must be declared at the top-level scope to list all Volumes used by services. In addition, to use a volume in a service, you must explicitly grant access by using the volumes attribute.

The db-volume is then mounted at /var/lib/mysql path for the database service.

For more information, refer to the corresponding section in our reference.

3. Launching the service #

Once the specification is defined, launch the service using

levv apply -f database.yml

To make effective use of your database service, check out our guide on communicating between services within a project. It covers how services can securely and reliably talk to each other.

As you’ve seen, levv simplifies persistent storage access for your services, ensuring that your information persists accross restarts.