Using Bitnami's Valkey chart

2024-07-09 · Rafael Ríos Saavedra

Valkey is a high-performance key/value datastore that supports workloads such as caching, and message queues, supporting many data types including strings, numbers, hashes, bitmaps, and more. Valkey can run in standalone or cluster mode for replication and high availability.

Bitnami offers a number of secure, up-to-date, and easy to deploy charts for a number of popular open source applications.

This blog will serve as a walk-through on how you can deploy and use the Bitnami Helm chart for Valkey.

Assumptions and prerequisites

Before starting the deployment, make sure that you have the following prerequisites:

Deploying the Bitnami package for the Valkey Helm chart

The sections below describe the steps to configure the deployment, get and deploy the Bitnami-package Valkey Helm chart, and obtain its external IP address to access the service.

Getting and deploying the Bitnami package for Valkey Helm chart

You can deploy the the community Bitnami-packaged Valkey Helm chart from the open source Bitnami Application Catalog. Alternatively, if you have access to an enterprise Tanzu Application Catalog instance, it can also be deployed from there.

Deploying the open source version of the chart through Bitnami Application Catalog

To deploy the chart in its namespace, run the following commands:

$ kubectl create namespace valkey
$ helm install myvalkey oci:// --set auth.enabled=true --set auth.password=test_pwd --namespace valkey

Deploying the enterprise version of the chart through Tanzu Application Catalog

The following steps describe navigating the Tanzu Application Catalog and getting the instructions to deploy Valkey in your cluster. This example shows a Valkey chart built using Ubuntu 22 as the base OS image, but feel free to customize the chart depending on your needs.

  1. Navigate to and sign in to your catalog with your VMware account. Tanzu Library
  2. In the My Applications section, search for Valkey and request it for your catalog. It is supported by Photon, Ubuntu, RHEL UBI, and Debian Linux distributions. On the next screen, you will find the instructions for deploying the chart on your cluster. Make sure that your cluster is up and running.
  3. Execute kubectl cluster-info, then run the commands you will find in the Consume your Helm chart section.

Tanzu Application Catalog

Bitnami Package Content

After this, the steps for deploying the chart will be the same as the ones described in the following sections to deploy its community version.

Obtaining the external IP address and logging into Valkey

Wait for the deployment to complete and check that all myvalkey pods are Running.

$ kubectl get pods,svc -n valkey
NAME                      READY   STATUS    RESTARTS   AGE
pod/myvalkey-master-0     1/1     Running   0          4m41s
pod/myvalkey-replicas-0   1/1     Running   0          4m41s
pod/myvalkey-replicas-1   1/1     Running   0          3m59s
pod/myvalkey-replicas-2   1/1     Running   0          3m32s

NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/myvalkey-headless   ClusterIP   None            <none>        6379/TCP   4m41s
service/myvalkey-master     ClusterIP   <none>        6379/TCP   4m41s
service/myvalkey-replicas   ClusterIP    <none>        6379/TCP   4m41s

Connecting using Valkey’s CLI client

To connect to the server, you can deploy a client pod.

$ export VALKEY_PASSWORD=test_pwd
$ kubectl run --namespace valkey valkey-client --restart='Never'  --env VALKEY_PASSWORD=$VALKEY_PASSWORD  --image --command -- sleep infinity

You are now ready to attach to the pod and interact with the server using the CLI client.

$ kubectl exec --tty -i valkey-client --namespace valkey -- bash
$ REDISCLI_AUTH="$VALKEY_PASSWORD" valkey-cli -h myvalkey-master
myvalkey-master:6379> set test_key "test_value"
myvalkey-master:6379> get test_key

Using a Python environment

The next example explains how to connect to Valkey using a Python script. To run the script, first, it is needed to provide a Python environment and install Python’s Redis package.

$ kubectl run -it  python-redis --image=bitnami/python -- bash
root@python-redis:/app# pip install redis
Collecting redis
Downloading redis-5.0.6-py3-none-any.whl.metadata (9.3 kB)
Downloading redis-5.0.6-py3-none-any.whl (252 kB)
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 252.0/252.0 kB 942.1 kB/s eta 0:00:00
Installing collected packages: redis
Successfully installed redis-5.0.6

You are now ready to run the script.

root@python-redis:/app# python
Python 3.12.4 (main, Jun  7 2024, 04:30:17) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> creds_provider = redis.UsernamePasswordCredentialProvider("", "test_pwd")
>>> user_connection = redis.Redis(host="myvalkey-master.valkey", port=6379, credential_provider=creds_provider)
>>> user_connection.set('foo_key', 'bar')
>>> user_connection.get('foo_key')
>>> user_connection.hset('user-session:123', mapping={
...     'name': 'John',
...     "surname": 'Smith',
...     "company": 'Redis',
...     "age": 29
... })
>>> user_connection.hgetall('user-session:123')
{b'name': b'John', b'surname': b'Smith', b'company': b'Redis', b'age': b'29'}

Using Valkey as a cache for WordPress

Valkey can also work as an object cache for a WordPress deployment. The following steps will show you how to set up this scenario.

First, it is needed to create the configuration for the WordPress deployment, in this case, Valkey’s parameters and the user credential for the site administrator are set.

$ cat > settings.yaml <<EOF
wordpressPassword: "wp_pwd"
wordpressExtraConfigContent: |
  define( 'WP_REDIS_HOST', 'myvalkey-master.valkey' );
  define( 'WP_REDIS_PORT', 6379 );
  define( 'WP_REDIS_PASSWORD', 'test_pwd' );
  define( 'WP_REDIS_PREFIX', 'wp_redis' );

Once you have the settings parameters, it is time to deploy WordPress in its namespace

$ kubectl create namespace wordpress
$ helm install mywp bitnami/wordpress -f settings.yaml --namespace wordpress

Wait for the deployment to complete and check that the service has been assigned an external IP

$ kubectl get svc --namespace wordpress
NAME                   TYPE         CLUSTER-IP     EXTERNAL-IP  PORT(S)         AGE
service/mywp-mariadb   ClusterIP  <none>       3306/TCP                    74s
service/mywp-wordpress LoadBalancer   80:31116/TCP,443:31119/TCP   74s

Using the external IP, browse to the admin page and log in using the previously set credentials.

You will be able to see the WordPress administrator UI where you can search for Redis Object Cache plugin, and then install and activate it. After enabling it, wait for some metrics to appear:

Redis Object Cache Metrics

This is only a drop in the bucket of what can be done with Valkey. Thereafter you could easily integrate Valkey into your projects.

Support and resources

The Bitnami package for Valkey is available in both the community version, through the Bitnami GitHub repository, as well as the enterprise version, Tanzu Application Catalog. Learn more about the differences between these two catalogs in this blog post.

To solve the problems you may have with the Bitnami community packages—including deployment support, operational support, and bug fixes—please open an issue in the Bitnami Helm charts or containers GitHub repositories. Also, if you want to contribute to the catalog, feel free to send us a pull request, and the team will check it and guide you in the process for a successful merge.

If you are interested in learning more about the Tanzu Application Catalog in general, check out the product webpage.