Zudoku
Guides

Redis

This guides shows you how to use Redis, an open-source in-memory storage, used as a distributed, in-memory key–value database, cache and message broker, with optional durability.

To run it example, 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/redis/ directory:

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

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 6379:6379/tls -M 512 .

The output shows the instance URL and other details:

TerminalCode
[] Deployed successfully! ────────── name: redis-alb4r ────────── uuid: d3c3141b-97b2-4e1d-87ae-39e4f14ab49e ───────── state: running ────────── fqdn: rough-wind-8vxrd1ms.fra0.kraft.host ───────── image: redis@sha256:9665c51faf7deb538cf7907b012b55700cad08cd391f5ba099d95d018c8da7d ───── boot time: 26.13 ms ──────── memory: 512 MiB ─────── service: rough-wind-8vxrd1ms ── private fqdn: redis-alb4r.internal ──── private ip: 172.16.6.2 ────────── args: /usr/bin/redis-server /etc/redis/redis.conf

In this case, the instance name is redis-alb4r; it's different for every run.

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

TerminalCode
kraft cloud tunnel 6379:memcached-arkv7:6379

Then, from another console, you can now use the redis-benchmark client to connect to Redis, for example:

Code
redis-benchmark -t ping,set,get -n 10000

You should see output similar to:

TerminalCode
====== PING_INLINE ====== 10000 requests completed in 32.03 seconds 50 parallel clients 3 bytes payload keep alive: 1 host configuration "save": host configuration "appendonly": no multi-thread: no 0.01% <= 138 milliseconds 0.05% <= 139 milliseconds 2.34% <= 140 milliseconds 4.49% <= 141 milliseconds 8.57% <= 142 milliseconds 16.06% <= 143 milliseconds 21.83% <= 144 milliseconds 26.25% <= 145 milliseconds 34.54% <= 146 milliseconds ...

To disconnect, simply kill the tunnel command with 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, ie, when a Redis 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 redis-alb4r rough-wind-8vxrd1ms.fra0.kraft... running 1 minute ago redis@sha256:9665c51faf7deb5... 512 MiB /usr/bin/redis-server /etc/red... 26131us

When done, you can remove the instance:

TerminalCode
kraft cloud instance remove redis-alb4r

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