Zudoku
Guides

MariaDB

This guide shows you how to use MariaDB, one of the most popular open source relational databases. To run it, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, e.g. Docker.

  2. Clone the examples repository and cd into the examples/mariadb/ directory:

TerminalCode
git clone https://github.com/kraftcloud/examples cd examples/mariadb

Make sure to log into Unikraft Cloud by setting your token and a metro close to you. We use fra0 (Frankfurt, ๐Ÿ‡ฉ๐Ÿ‡ช) in this guide:

TerminalCode
# Set Unikraft Cloud access token export UKC_TOKEN=token # Set metro to Frankfurt, DE export UKC_METRO=fra0

When done, invoke the following command to deploy this application on Unikraft Cloud:

TerminalCode
kraft cloud deploy -p 3306:3306/tls -M 1024 .

The output shows the instance URL and other details:

TerminalCode
[โ—] Deployed successfully! โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ name: mariadb-w2g2z โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ uuid: ba696c22-adff-4fba-88b9-d1b790ca2357 โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ state: running โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ fqdn: twilight-sun-82lt4ddk.fra0.kraft.host โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ image: mariadb@sha256:6e31d28b351eb12a070e3074f0a500532d0a494332947e9d8dbfa093d2d551fd โ”œโ”€โ”€โ”€โ”€โ”€ boot time: 159.06 ms โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ memory: 1024 MiB โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€ service: twilight-sun-82lt4ddk โ”œโ”€โ”€ private fqdn: mariadb-w2g2z.internal โ”œโ”€โ”€โ”€โ”€ private ip: 172.16.6.3 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ args: /usr/sbin/mariadbd --user=root --log-bin

In this case, the instance name is mariadb-w2g2z; it is different for each run.

To test the deployment, first forward the port with the kraft cloud tunnel command.

TerminalCode
kraft cloud tunnel 3306:mariadb-w2g2z:3306

You can now, on a separate console, use the mysql command line tool to test that the set up works:

TerminalCode
mysql -h 127.0.0.1 --ssl-mode=DISABLED -u root -punikraft mysql <<< "select count(*) from user"

Alternatively, use the mariadb client command line tool:

TerminalCode
mariadb -h 127.0.0.1 --ssl=OFF -u root -punikraft mysql <<< "select count(*) from user"

You should see output such as:

TerminalCode
count(*) 6

To disconnect, kill the tunnel command using Ctrl+c.

We use kraft cloud tunnel only when a service doesn't support TLS and is not HTTP-based (we use TLS/SNI to determine the correct instance to send traffic to). Also note that tunnel command is not needed when connecting via an instance's private IP/FQDN; i.e., when a MariaDB instance is used as a backend to another instance that acts as a frontend and which does support TLS.

At any point in time, you can list information about the instance:

TerminalCode
kraft cloud instance list
Code
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIME mariadb-w2g2z twilight-sun-82lt4ddk.fra0.kra... running 1 minute ago mariadb@s... 1.0 GiB /usr/sbin/mariadbd --user=ro... 159065us

When done, you can remove the instance:

TerminalCode
kraft cloud instance remove mariadb-w2g2z

Customize your Application

To customize the application, update the files in the repository, listed below:

  • Kraftfile: the Unikraft Cloud specification, including command-line arguments
  • Dockerfile: In case you need to add files to your instance's rootfs

Learn More

Use the --help option for detailed information on using Unikraft Cloud:

TerminalCode
kraft cloud --help

Or visit the CLI Reference.

Last modified on