Deploy 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:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/redis/
directory:
git clone https://github.com/kraftcloud/examplescd 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:
# Set Unikraft Cloud access tokenexport UKC_TOKEN=token# Set metro to Frankfurt, DEexport UKC_METRO=fra0
When done, invoke the following command to deploy this application on Unikraft Cloud:
kraft cloud deploy -p 6379:6379/tls -M 512 .
The output shows the instance URL and other details:
[β] 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:
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:
redis-benchmark -t ping,set,get -n 10000
You should see output similar to:
====== 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 milliseconds0.05% <= 139 milliseconds2.34% <= 140 milliseconds4.49% <= 141 milliseconds8.57% <= 142 milliseconds16.06% <= 143 milliseconds21.83% <= 144 milliseconds26.25% <= 145 milliseconds34.54% <= 146 milliseconds...
To disconnect, simply kill the tunnel
command with ctrl-C
At any point in time, you can list information about the instance:
kraft cloud instance list
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIMEredis-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:
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 argumentsDockerfile
: In case you need to add files to your instanceβs rootfs
spec: v0.6
runtime: redis:latest
rootfs: ./Dockerfile
cmd: ["/usr/bin/redis-server", "/etc/redis/redis.conf"]
FROM debian:bookworm AS build
RUN set -xe; \ echo "Your code here";
FROM scratch
# Copy your files here# COPY --from=build / /
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
kraft cloud --help
Or visit the CLI Reference.