Zudoku
Guides

Memcached

This guide shows you how to use Memcached. Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

To run it, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, for example Docker.

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

Code(bash)
git clone https://github.com/kraftcloud/examples cd examples/memcached/

Make sure to log into Unikraft Cloud by setting your token and a metro close to you. This guide uses fra (Frankfurt, ๐Ÿ‡ฉ๐Ÿ‡ช):

Code(bash)
# Set Unikraft Cloud access token export UKC_TOKEN=token # Set metro to Frankfurt, DE export UKC_METRO=fra

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

Code(bash)
kraft cloud deploy -p 11211:11211/tls -M 256 .

The output shows the instance address and other details:

Code(ansi)
[โ—] Deployed successfully! โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ name: memcached-arkv7 โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ uuid: da436eca-bc64-46d7-a04c-72832652b10e โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ state: running โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ fqdn: weathered-smoke-hehsdinv.fra.unikraft.app โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ image: memcached@sha256:f53cdbce4dc185e8acc8ecb93a0ab0ba99085ca0837a0ad2062aae9e31382e58 โ”œโ”€โ”€โ”€โ”€โ”€ boot time: 19.27 ms โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ memory: 256 MiB โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€ service: weathered-smoke-hehsdinv โ”œโ”€โ”€ private fqdn: memcached-arkv7.internal โ”œโ”€โ”€โ”€โ”€ private ip: 172.16.6.5 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ args: /usr/bin/memcached -u root

In this case, the instance name is memcached-arkv7 which is different for each run.

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

Code(bash)
kraft cloud tunnel 11211:memcached-arkv7:11211

Now, on a separate console, run the following commands to test that it works (you should see output when incrementing):

Code
telnet 127.0.0.1 11211 set test 0 0 1 0 incr test 1 incr test 1

To exit telnet run:

Code
Ctrl + ] Ctrl + C

To disconnect, kill the tunnel command with ctrl-C.

This guide uses kraft cloud tunnel only when a service doesn't support TLS and isn't HTTP-based (TLS/SNI determines the correct instance to send traffic to). Also note that the tunnel command isn't needed when connecting via an instance's private IP/FQDN. For example when a Memcached instance serves as a cache server to another instance that acts as a frontend and which does support TLS.

You can list information about the instance by running:

Code(bash)
kraft cloud instance list
Code(text)
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIME memcached-arkv7 weathered-smoke-hehsdinv.fra.unikraft.app running 11 minutes ago memcached@sha256:f53cdbce4... 256 MiB /usr/bin/memcached -u root 19266us

When done, you can remove the instance:

Code(bash)
kraft cloud instance remove memcached-arkv7

Customize your app

To customize the app, 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:

Code(bash)
kraft cloud --help

Or visit the CLI Reference.

Last modified on