Skip to content

Install highly available Valkey with Sentinel#

In the Valkey with Sentinel architecture, Sentinel nodes monitor the Valkey primary and replica nodes and automatically promote a replica if the primary fails. MSR 4 queries Sentinel to find the current primary, so it continues to work after a failover. Valkey with Sentinel requires Valkey Helm chart 1.0.0 or later.

Deploy Valkey with Sentinel#

  1. Generate a strong, random password for authenticating with Valkey:

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

    kubectl create secret generic msr-valkey-secret \
       --from-literal=REDIS_PASSWORD=${PASSWORD}
    

    Note

    MSR 4 requires REDIS_PASSWORD as the password field name.

  3. Deploy the Valkey with Sentinel instance in the MSR 4 namespace:

    helm install msr-valkey oci://registry.mirantis.com/harbor/helm/mirantis-valkey/valkey \
        --version 1.0.0 \
        --set replica.enabled=true \
        --set replica.replicas=3 \
        --set persistence.enabled=true \
        --set persistence.size=10Gi \
        --set auth.enabled=true \
        --set auth.usersExistingSecret=msr-valkey-secret \
        --set auth.aclUsers.default.passwordKey=REDIS_PASSWORD \
        --set "auth.aclUsers.default.permissions=~* &* +@all" \
        --set sentinel.enabled=true \
        --set sentinel.replicas=3 \
        --set sentinel.auth.enabled=false \
        --set networkPolicy.enabled=true \
        --set "networkPolicy.ingressNSMatchLabels.kubernetes\.io/metadata\.name=<msr-namespace>"
    

    Configuration considerations:

    • The replica.replicas value specifies the total number of Valkey nodes, including the primary node. The sentinel.replicas value specifies the number of Sentinel nodes. The default is 3.
    • MSR 4 cannot authenticate to Sentinel, so set sentinel.auth.enabled=false. The chart then requires networkPolicy.enabled=true and allows access to the Sentinel port only from the following sources:

      • The Valkey and Sentinel pods of the release
      • Pods labeled msr-valkey-client: "true"
      • The namespace set in networkPolicy.ingressNSMatchLabels, which must be the MSR 4 namespace

      This protection applies only if your cluster network plugin enforces NetworkPolicies.

  4. Retrieve the connection details for the Valkey service:

    1. Get the Sentinel master name:

      kubectl exec msr-valkey-sentinel-0 -- valkey-cli -p 26379 --raw SENTINEL MASTERS | sed -n 2p
      
    2. Get the name and port number of the Sentinel headless service:

      kubectl get svc | grep valkey
      

      Example output:

      msr-valkey               ClusterIP   <cluster-ip>   <none>        6379/TCP    34s
      msr-valkey-headless      ClusterIP   None           <none>        6379/TCP    34s
      msr-valkey-read          ClusterIP   <cluster-ip>   <none>        6379/TCP    34s
      msr-valkey-sentinel      ClusterIP   <cluster-ip>   <none>        26379/TCP   34s
      msr-valkey-sentinel-hl   ClusterIP   None           <none>        26379/TCP   34s
      

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

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

    • The addr value specifies a comma-separated list of Sentinel pod addresses in the <pod-name>.<headless-service-name>.<namespace>.svc.cluster.local:<port> format. In the example below, replace default with your MSR 4 namespace.
    • The sentinelMasterSet value specifies the master name defined during the Sentinel deployment. The default is mymaster.

    Example configuration:

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

Enable Sentinel on an Existing Valkey Deployment with Replication#

  1. Run the helm upgrade command from Upgrade Valkey with Sentinel against the existing msr-valkey release:

    • If the release uses chart version 0.x, set --version to 1.0.0 or later. In that case, do not use --reuse-values.
    • With replica.replicas=3, the upgrade keeps the existing primary and the two replicas. The data volumes stay in place.
  2. Update the MSR 4 Redis configuration as described in step 5 of Deploy Valkey with Sentinel.

  3. Apply the updated configuration to MSR 4, setting --version to the MSR 4 version that you run:

    helm upgrade <release-name> oci://registry.mirantis.com/harbor/helm/msr \
      --version <msr-version> \
      -f values.yaml
    

    Until MSR 4 uses Sentinel, it can send writes to a replica and some requests can fail.