Skip to content

Install highly available Redis with Sentinel#

  1. Install the Redis Operator from the OT-Container-Kit Helm repository:

    helm install redis-operator redis-operator \
          --repo https://ot-container-kit.github.io/helm-charts \
          --set featureGates.GenerateConfigInInitContainer=true
    
  2. Generate a strong, random password for authenticating with Redis:

    PASSWORD=$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 24)
    
  3. Create a Kubernetes secret to securely store the password:

    kubectl create secret generic msr-redis-secret \
       --from-literal=REDIS_PASSWORD=${PASSWORD}
    
  4. Deploy the Redis with Sentinel instance:

    Note

    Set clusterSize and sentinel.size to the desired number of Redis nodes.

    helm install msr-redis redis-replication \
        --repo https://ot-container-kit.github.io/helm-charts \
        --set redisReplication.clusterSize=3 \
        --set redisReplication.image=quay.io/opstree/redis \
        --set redisReplication.tag=v7.2.13 \
        --set redisReplication.redisSecret.secretName=msr-redis-secret \
        --set redisReplication.redisSecret.secretKey=REDIS_PASSWORD \
        --set podSecurityContext.runAsUser=1000 \
        --set podSecurityContext.fsGroup=1000 \
        --set sentinel.enabled=true \
        --set sentinel.size=3 \
        --set sentinel.image=quay.io/opstree/redis-sentinel \
        --set sentinel.tag=v7.2.13 \
        --set storageSpec.volumeClaimTemplate.spec.accessModes={ReadWriteOnce} \
        --set storageSpec.volumeClaimTemplate.spec.resources.requests.storage=8Gi
    
  5. Retrieve the connection details for the Redis service:

    Get the Sentinel master name:

    kubectl -n default get redisreplication msr-redis -o jsonpath='{.status.connectionInfo. masterName}{"\n"}'
    

    Get the Sentinel headless service's name and port number:

    kubectl get svc | grep redis
    
    i.e.
    msr-redis                ClusterIP   10.96.169.88    <none>        6379/TCP                     34s
    msr-redis-additional     ClusterIP   10.96.57.50     <none>        6379/TCP                     34s
    msr-redis-headless       ClusterIP   None            <none>        6379/TCP                     34s
    msr-redis-master         ClusterIP   10.96.57.51     <none>        6379/TCP                     34s
    msr-redis-replica        ClusterIP   10.96.33.204    <none>        6379/TCP                     34s
    msr-redis-s-hl           ClusterIP   None            <none>        26379/TCP     
    

    In the example above, msr-redis-s-hl is Sentinel headless service which uses port 26379.

  6. In values.yml, configure the Redis connection fields using the Sentinel service, port, and master name:

    • addr — Comma-separated list of Sentinel pod addresses in the following format: <pod-name>.<headless-service-name>.<namespace>.svc.cluster.local:<port>
    • sentinelMasterSet — Master name defined during Sentinel deployment (for example, mymaster).

    Example configuration:

    redis:
        type: external
        external:
            addr: "msr-redis-s-0.msr-redis-s-hl.default.svc.cluster.local:26379,msr-redis-s-1.msr-redis-s-hl.default.svc.cluster.local:26379,msr-redis-s-2.msr-redis-s-hl.default.svc.cluster.local:26379"
            existingSecret: msr-redis-secret
            sentinelMasterSet: "mymaster"
    

Upgrade highly available Redis#

  1. Verify Redis version:

    kubectl get pod <Redis Pod> -o jsonpath='{.spec.containers[*].image}'
    kubectl get pod <Sentinel Pod> -o jsonpath='{.spec.containers[*].image}'
    
  2. Upgrade Redis:

    helm upgrade msr-redis redis-replication \
        --repo https://ot-container-kit.github.io/helm-charts \
        --set redisReplication.clusterSize=3 \
        --set redisReplication.image=quay.io/opstree/redis \
        --set redisReplication.tag=v7.2.13 \
        --set redisReplication.redisSecret.secretName=msr-redis-secret \
        --set redisReplication.redisSecret.secretKey=REDIS_PASSWORD \
        --set podSecurityContext.runAsUser=1000 \
        --set podSecurityContext.fsGroup=1000 \
        --set sentinel.enabled=true \
        --set sentinel.size=3 \
        --set sentinel.image=quay.io/opstree/redis-sentinel \
        --set sentinel.tag=v7.2.13 \
        --set storageSpec.volumeClaimTemplate.spec.accessModes={ReadWriteOnce} \
        --set storageSpec.volumeClaimTemplate.spec.resources.requests.storage=8Gi
    

    Note

    Mirantis recommends Redis 7.2.11 or later within 7.2.x branch. The validated versions are 7.2.11, 7.2.12, and 7.2.13. For the full list of available versions, see the redis-operator page.