Wednesday, 13 August 2025

Setup Redis Cluster with JSON and Search Modules on AKS with Binami Redis Using Custom Image

 We have discussed "Build Custom Docker Images with Redis Json and Search Module Support for deploying Bitnami Redis Cluster and Standalone in AKS" previously. We have cfreated a cutom redis cluster image including the redis modules json, search etc. In this post let's explore how to setup Redis cluster on AKS using binami helm chart, while using the custom built image. The usage of custom built image is required to have the json and search modules available as described in the post "Build Custom Docker Images with Redis Json and Search Module Support for deploying Bitnami Redis Cluster and Standalone in AKS".

Note that the redis cluster deployed to AKS or to kubernetes can be only accessed withing the kubernetes cluster. Therefore, only the apps deployed to AKS/kubernetes can only access the redis endpoint in redis cluster on AKS. For allowing local development with redis on AKS, we need to setup bitnami redis standalone mode, which we will discuss in a future post.

The expectation is to have an up and running Redis cluster in AKS with json and search modules as shown below.



The first step is to setup a namespace for Redis in the AKS cluster. Lets set it up as redis using below yaml. You can create a yaml file with below content and apply it with kubectl apply command.

Example: kubectl apply -f k8s_system_prerequisites.yaml.

# Namespace in AKS for Redis
---
apiVersion: v1
kind: Namespace
metadata:
  name: redis

Then we have to setup a storage class and a secret for keeping redis password. Here the ${redis_password}$ should be replaced with the actual password value. Can be done via token replacement in Azure pipelines.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  labels:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/name: redis
    app.kubernetes.io/part-of: redis
  name: redis-storage
parameters:
  skuName: StandardSSD_LRS
  fsType: ext4
provisioner: disk.csi.azure.com
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

---
apiVersion: v1
kind: Secret
metadata:
  name: redis-service-credentials
  namespace: redis
type: Opaque
stringData:
  password: ${redis_password}$

The password can be creatd via terraform as shown below and added to Azure KeyVault and use it via Azure app configurations for applications accessing the Redis

resource "random_password" "redis_password" {
  length           = 32
  special          = true
  override_special = "-_@!()"
  min_numeric      = 1
  min_upper        = 1
  min_lower        = 1
  min_special      = 1
}

Run below command to get bitnami helm chart repos.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

Then we can use below helm command to deploy the Redis cluster. 

    helm upgrade redis-cluster bitnami/redis-cluster --install \
        --namespace redis \
        --version 12.0.13 \
        --set redis.nodeSelector."kubernetes\.io/os"=linux \
        --set redis.podAntiAffinityPreset=soft \
        --set global.defaultStorageClass=redis-storage \
        --set persistence.enabled=true \
        --set redis.useAOFPersistence="yes" \
        --set persistentVolumeClaimRetentionPolicy.enabled=true \
        --set persistentVolumeClaimRetentionPolicy.whenDeleted=Delete \
        --set existingSecret=redis-service-credentials \
        --set existingSecretPasswordKey=password \
        --set redis.extraEnvVars[0].name=REDIS_EXTRA_FLAGS \
        --set redis.extraEnvVars[0].value="--loadmodule /opt/redis/modules/redisbloom.so --loadmodule /opt/redis/modules/redisearch.so --loadmodule /opt/redis/modules/redistimeseries.so --loadmodule /opt/redis/modules/rejson.so" \
        --set cluster.nodes=9 \
        --set cluster.replicas=2 \
        --set pdb.create=true \
        --set pdb.minAvailable="50%" \
        --set persistence.size=16Gi \
        --set redis.resources.requests.memory=4Gi \
        --set redis.resources.limits.memory=4Gi \
        --set redis.resources.requests.cpu=500m \
        --set global.security.allowInsecureImages=true \
        --set image.registry=chdemoacr.azurecr.io \
        --set image.repository=ch/redis/ch_redis_cluster \
        --set image.tag=8.0.3-debian-12-r2

Lets try to understand each part of above helm command.

Below part says install or upgrade existing installation and use redis namespace to deploy redis cluster.

helm upgrade redis-cluster bitnami/redis-cluster --install \
        --namespace redis \
        --version 12.0.13

Then in below part we specify node selector to be linuux and let pods to be created with soft affinity as described in bitnami redis docs here. Enabling persitence is required to ensure no data loss due to pod restarts.

--set redis.nodeSelector."kubernetes\.io/os"=linux \
--set redis.podAntiAffinityPreset=soft \
--set global.defaultStorageClass=redis-storage \
--set persistence.enabled=true \
--set redis.useAOFPersistence="yes" \
--set persistentVolumeClaimRetentionPolicy.enabled=true \
--set persistentVolumeClaimRetentionPolicy.whenDeleted=Delete

Then we setup password for redis here. The secret reference and its key which keep password is given here. password should not be actiual password value. It should just be the name of password key in the kubernetes secret which is just the word password  in this case. Refer the redis-service-credentials  above.

--set existingSecret=redis-service-credentials \
--set existingSecretPasswordKey=password

The module such as json we have added them to the bitnami redis image using the custom image creation as described in the post "Build Custom Docker Images with Redis Json and Search Module Support for deploying Bitnami Redis Cluster and Standalone in AKS". Here we need to ensure they are loaded in the deployed redis cluster. For that we need to setup env variable REDIS_EXTRA_FLAGS with the values shown below.

--set redis.extraEnvVars[0].name=REDIS_EXTRA_FLAGS \
--set redis.extraEnvVars[0].value="--loadmodule /opt/redis/modules/redisbloom.so --loadmodule /opt/redis/modules/redisearch.so --loadmodule /opt/redis/modules/redistimeseries.so --loadmodule /opt/redis/modules/rejson.so" \

Below determine the cluster size and the resource utilization. With below there will be three master nodes and each master will have 2 replica nodes in redis clsuter altogether making it 9 nodes. A pod disruption budget will be setup with 50% min availability ensuring reliability of Redis clsuter on AKS. The cpu has no limit set to aavoid throttling and memory limit and persitence disk size need to be monitored with production usage and increased if necessary.

--set cluster.nodes=9 \
--set cluster.replicas=2 \
--set pdb.create=true \
--set pdb.minAvailable="50%" \
--set persistence.size=16Gi \
--set redis.resources.requests.memory=4Gi \
--set redis.resources.limits.memory=4Gi \
--set redis.resources.requests.cpu=500m \

Finally we can have the custom image set as shown below so it will be puuled form the Azure contianer registry attached to the AKS. Allow insecure images is required to allow the usage of custom image.

--set global.security.allowInsecureImages=true \
--set image.registry=chdemoacr.azurecr.io \
--set image.repository=ch/redis/ch_redis_cluster \
--set image.tag=8.0.3-debian-12-r2

After deploying the helm chart we would be able to see the cluster is starting up in the AKS and evetually be ready after few minutes as shown below.


Let's see how to setup redis insight to connect to the redis cluster on AKS and work with it in the next post.

No comments:

Popular Posts