Tuesday, 2 September 2025

Setup Redis Standalone with JSON and Search Modules on AKS with Binami Redis Using Custom Image to Allow Local Development

 As we discusssed in  "Setup Redis Cluster with JSON and Search Modules on AKS with Binami Redis Using Custom Image" the cluster deployemnt does not allow the redis to be accessed outside of AKS/kubernetes. To allow local development with redis we have to deploy redis standalone on AKS. Ideally the standalone should be setup in development environment and clsuter mode should be setup in QA and production environments. Let's look at how to setup redis standalone with json and search modules using custom image we built in "Build Custom Docker Images with Redis Json and Search Module Support for deploying Bitnami Redis Cluster and Standalone in AKS".

The expectaion is to have redis deployed in standalone mode as shwon below.

The prerequisites are same as descibed in "Setup Redis Cluster with JSON and Search Modules on AKS with Binami Redis Using Custom Image". Namespace redis, storage class and redis password secret should be setup as prerequisites.

Run below command to get bitnami helm chart repos.

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

The helm command to setup redis standalone with bitnami helm using custom image with json and search modules is below.

helm upgrade redis-standalone bitnami/redis --install \
    --namespace redis \
    --version 21.2.12 \
    --set master.nodeSelector."kubernetes\.io/os"=linux \
    --set replica.nodeSelector."kubernetes\.io/os"=linux \
    --set global.defaultStorageClass=redis-storage \
    --set master.persistence.enabled=true \
    --set replica.persistence.enabled=true \
    --set master.persistentVolumeClaimRetentionPolicy.enabled=true \
    --set replica.persistentVolumeClaimRetentionPolicy.enabled=true \
    --set master.persistentVolumeClaimRetentionPolicy.whenDeleted=Delete \
    --set replica.persistentVolumeClaimRetentionPolicy.whenDeleted=Delete \
    --set replica.replicaCount=2 \
    --set auth.existingSecret=redis-service-credentials \
    --set auth.existingSecretPasswordKey=password \
    --set master.extraFlags="{--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 replica.extraFlags="{--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 master.persistence.size=16Gi \
    --set replica.persistence.size=16Gi \
    --set master.resources.requests.memory=4Gi \
    --set master.resources.limits.memory=4Gi \
    --set master.resources.requests.cpu=500m \
    --set replica.resources.requests.memory=4Gi \
    --set replica.resources.limits.memory=4Gi \
    --set replica.resources.requests.cpu=500m \
    --set global.security.allowInsecureImages=true \
    --set image.registry=chdemoacr.azurecr.io \
    --set image.repository=ch/redis/ch_redis_standalone \
    --set image.tag=8.0.3-debian-12-r2

Lets try to understand the above helm command. Refer bitnami redis standalone docs here.

Below says the redis standalone to be installed or update if exists. We have to say both master and replica pod should schedule inn linux nodes in AKS. The we are setting storage class here and setup persistence for master and replicas.

helm upgrade redis-standalone bitnami/redis --install \
    --namespace redis \
    --version 21.2.12 \
    --set master.nodeSelector."kubernetes\.io/os"=linux \
    --set replica.nodeSelector."kubernetes\.io/os"=linux \
    --set global.defaultStorageClass=redis-storage \
    --set master.persistence.enabled=true \
    --set replica.persistence.enabled=true \
    --set master.persistentVolumeClaimRetentionPolicy.enabled=true \
    --set replica.persistentVolumeClaimRetentionPolicy.enabled=true \
    --set master.persistentVolumeClaimRetentionPolicy.whenDeleted=Delete \
    --set replica.persistentVolumeClaimRetentionPolicy.whenDeleted=Delete \

Then we can defin the replicacount and the credentials. Here only one master is created to allow accessibility from outside the AKS cluster. We can have more replica pods if required.

    --set replica.replicaCount=2 \
    --set auth.existingSecret=redis-service-credentials \
    --set auth.existingSecretPasswordKey=password \

Unlike in the cluster mode we have to use a different mechanism in standalone mode to allow loading the search and json modules we added to custom image.  This should be done as shown below for both master and replicas.

--set master.extraFlags="{--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 replica.extraFlags="{--loadmodule\ /opt/redis/modules/redisbloom.so,--loadmodule\ /opt/redis/modules/redisearch.so,--loadmodule\ /opt/redis/modules/redistimeseries.so,--loadmodule\ /opt/redis/modules/rejson.so}" \
    

Then we set the resources and custom image details.

    --set master.persistence.size=16Gi \
    --set replica.persistence.size=16Gi \
    --set master.resources.requests.memory=4Gi \
    --set master.resources.limits.memory=4Gi \
    --set master.resources.requests.cpu=500m \
    --set replica.resources.requests.memory=4Gi \
    --set replica.resources.limits.memory=4Gi \
    --set replica.resources.requests.cpu=500m \
    --set global.security.allowInsecureImages=true \
    --set image.registry=chdemoacr.azurecr.io \
    --set image.repository=ch/redis/ch_redis_standalone \
    --set image.tag=8.0.3-debian-12-r2

Once deployed we can see one master pod and two replica pods running for redis standalone.Two stateful sets are there for master and replica pods. Redis insight can be deployed as described in "Deploy Redis Insights on AKS to View/Update Data in Redis Cluster Deployed to AKS" with redis standalone as well. The standalone  "${redis_aks_route}$" value will be redis-standalone-master.redis.svc.cluster.local  for a standalone deployment made in namespace redis, and that should be used to setup redis insight to allow access to redis standalone suing env variable RI_REDIS_HOST.


To allow local development access we need to setup a loadbalancer for dev with standalone redis on AKS as shown below. If you have VPN setup with Azure you can use private IP load balancer to allow local access.

# Load balancer service for redis standalone to allow local development
---
apiVersionv1
kindService
metadata:
  nameredis-dev-lb
  namespaceredis
  labels:
    appredis-standalone-master
    redis_setup_typestandalone
    rolemaster
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-ipv4${public_ip_redis}$
    service.beta.kubernetes.io/azure-load-balancer-internal"false"
    # Private IP for redis service
    # This can be used only with VPN. Therefore, above public IP used.
    # ---------------
    # service.beta.kubernetes.io/azure-load-balancer-ipv4: #{private_ip_redis}# replace # with $
    # service.beta.kubernetes.io/azure-load-balancer-internal: "true"
    # ---------------
spec:
  typeLoadBalancer
  selector:
    app.kubernetes.io/componentmaster
    app.kubernetes.io/instanceredis-standalone
    app.kubernetes.io/nameredis
  ports:
    - nameredis
      protocolTCP
      port6379
      targetPort6379

This allows you to setup private DNS zone for AKS deloyed redis stadalone and access it via .NET code as shown in below code.

            // Redis configuration
            ConfigurationOptions redisConfig = new()
            {
                EndPoints = { "redis.aksblue.fw-av-dev-euw-001.net:6379" },
                Password = "passwordhere",
                ClientName = "chaminda-laptop-guid",
                AbortOnConnectFail = false
            };

            // Connect and get the database
            var redis = await ConnectionMultiplexer.ConnectAsync(redisConfig);
            db = redis.GetDatabase(0);


No comments:

Popular Posts