← Back to Guides
Profile image for Humberto Leal
Published 23rd March 2022

Deploy KeyDB on Northflank

KeyDB is a high performance fork of Redis with a focus on multithreading, memory efficiency, and high throughput. KeyDB, a Redis alternative, still has full and absolute compatibility with Redis and straightforward clustering and sharding without the need for Sentinel and other auxiliary software. By the end of this guide, you will have a KeyDB database running on Northflank. Let’s get to it!

Service creation and configuration

  1. Create a new service.

  2. Select Deployment as the Service type.

    service_creation

  3. Select external image and eqalpha/keydb:latest as image path.

    image_path

  4. Configure the 6379 TCP port on the service.

    • KeydDB service will be only available internally. In case you need to connect to it from your machine, Northflank forwarder will be required.

    port_config

Use Northflank forwarding and connect the service

  1. Start the forwarding of the service through the Northflank CLI.

    terminal-forwarding-keydb

  2. Using the redis-cli, for a service called keydb, connect to it using the following string:
    redis-cli -h keydb

  3. Once connected you can start running commands. For example:
    set hello bye
    get hello

    nf_forward_ok

Configure authentication

In order to enable authentication you can rely on the requirepass parameter when starting the server.

  1. First let’s create a proper password string. Jump to the Environment tab in the Service Dashboard and create a new one through the Generate secret values. Name the new environment variable KEYDB_PASSWORD. Commit the changes.

    env_variables

  2. Now go to the CMD Override tab.

    1. Once there, edit the command through the Edit commands button.

    2. Enable the Use override option. Then, replace the CMD Override text field with the following command:

      /bin/sh -c “keydb-server /etc/keydb/keydb.conf --requirepass $KEYDB_PASSWORD”

      • The `/bin/sh` is required for the KEYDB_PASSWORD environment variable to be correctly processed as the `requirepass` argument value.
    3. Commit the changes through the Save & restart button.

      cmd_override

    4. Wait for the container to start up again.

Connect to KeyDB using password

  1. You may have to restart the forwarder given that the container was restarted. Once the forwarder is running and using the redis-cli, use the following arguments to connect to it:

    $KEYDB_PASSWORD=<copy value from northflank ui> redis-cli -h keydb -a $KEYDB_PASSWORD

  2. Check that you’re able to run commands as shown previously.

    • You may notice that when querying the keys created previously they no longer exist. This is because persistence for this container is not enabled.

    nf_cli_commands

Configure persistence for KeyDB

Service persistence

In order to avoid data loss between restarts or outages, we first need to provision persistence storage to our service.

  1. Head over to the Volumes tab and add a new volume.

  2. Select proper storage space according to your requirements. In this case we’re going to use 5GB.

  3. The Keydb container uses the /data path to store all of its data. Make sure to put /data as the Container mount path.

  4. Confirm the changes through Create & attach volume.

    keydb_volumes

KeyDB durable persistence through appendonly mode

KeyDB by default will use snapshot persistence, which stores changes on a file after a certain number of commands or a certain amount of time has elapsed.

This is not very durable as the latest changes written to KeyDB may not get written to the snapshot file. Read more on KeyDB persistence on their docs.

To have a more durable persistence, we use the append only mode, which appends changes on a file each time the data set has been changed.

  1. In order to enable it we have to head over to the CMD Override tab and then pass the --appendonly yes argument to the initial command.

  2. The final version including authentication is as follows:
    /bin/sh -c "keydb-server /etc/keydb/keydb.conf --requirepass $KEYDB_PASSWORD –appendonly yes"

    cmd_final

  3. Commit the changes

Verify changes

  1. Wait for the container to start up correctly.

  2. Connect to it using the forwarder or a Redis client, for example Redis Commander. This guide shows you how to deploy Redis Commander on Northflank.

  3. Start running commands that store data on KeyDB.

  4. Perform a restart.

  5. Connect again and verify that the data is still present on KeyDB.

Using Northflank to deploy KeyDB

Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.

  • Deployment of Docker containers
  • Create your own stateful workloads
  • Persistent volumes
  • Observe & monitor with real-time metrics & logs
  • Low latency and high performance
  • Multiple read and write replicas
  • Backup, restore and fork databases
Share this article with your network
X