Redis cluster (with KeyDB)

In this example, we'll deploy KeyDB Cluster and Redis Insight.
We'll also add a load balancer (HAProxy) to distribute traffic between both KeyDB. Services will be able to connect to this load balancer, which will be highly available.

1. Create KeyDB cluster + Redis Insight

services:
  - id: redis1
    name: Redis Node 1
    dockerConfiguration:
      image: eqalpha/keydb
      imageVersion: latest
      args: keydb-server --active-replica yes --replicaof 127.0.0.1 6382
    countMin: 1
    countMax: 1
    capacityCpuMhz: 1024
    capacityMemoryMB: 128
    ports:
      - listeningPort: 6379
        healthCheckEnabled: false
    links:
      - toServiceId: redis2
        toServicePort: 6379
        localExposedPort: 6382
        variableHost: REDIS2_HOST
        variablePort: REDIS2_PORT
        variableAddress: REDIS2_ADDR
  - id: redis2
    name: Redis Node 2
    dockerConfiguration:
      image: eqalpha/keydb
      imageVersion: latest
      args: keydb-server --active-replica yes --replicaof 127.0.0.1 6381
    countMin: 1
    countMax: 1
    capacityCpuMhz: 1024
    capacityMemoryMB: 128
    ports:
      - listeningPort: 6379
        healthCheckEnabled: false
    links:
      - toServiceId: redis1
        toServicePort: 6379
        localExposedPort: 6381
        variableHost: REDIS1_HOST
        variablePort: REDIS1_PORT
        variableAddress: REDIS1_ADDR
  - id: redisinsight
    name: Redis Insight
    dockerConfiguration:
      image: oblakstudio/redisinsight
      imageVersion: latest
    ports:
      - listeningPort: 5540
        loadBalancerRules:
          - publicPort: 443
    links:
      - toServiceId: redis1
        toServicePort: 6379
        localExposedPort: 6379
        variableHost: REDIS1_HOST
        variablePort: REDIS1_PORT
        variableAddress: REDIS1_ADDR
      - toServiceId: redis2
        toServicePort: 6379
        localExposedPort: 6380
        variableHost: REDIS2_HOST
        variablePort: REDIS2_PORT
        variableAddress: REDIS2_ADDR
    capacityCpuMhz: 512
    capacityMemoryMB: 512
Be careful! In production, you probably don't want to expose your insecure Redis Insight to the public.

2. Create KeyDB load balancer

services:
  - id: redislb
    name: Redis LB
    dockerConfiguration:
      image: haproxy
      imageVersion: latest
    ports:
      - listeningPort: 6380
        healthCheckEnabled: false
    links:
      - toServiceId: redis1
        toServicePort: 6379
        localExposedPort: 6381
        variableHost: REDIS1_HOST
        variablePort: REDIS1_PORT
        variableAddress: REDIS1_ADDR
      - toServiceId: redis2
        toServicePort: 6379
        localExposedPort: 6382
        variableHost: REDIS2_HOST
        variablePort: REDIS2_PORT
        variableAddress: REDIS2_ADDR
    countMin: 2
    countMax: 2
    files:
      - path: /usr/local/etc/haproxy/haproxy.cfg
        interpolate: true
        content: |
          global
          log /dev/log    local0
          log /dev/log    local1 notice
          stats timeout 30s
          user haproxy
          group haproxy

          defaults
              log global
              mode    http
              option  httplog
              option  dontlognull
                  timeout connect 5000
                  timeout client  50000
                  timeout server  50000

          listen mykeydb 
              bind *:6380
              maxconn 40000 
              mode tcp
              balance first
              option tcplog
              option tcp-check
              tcp-check send PING\r\n
              tcp-check expect string +PONG
              tcp-check send QUIT\r\n
              tcp-check expect string +OK
              server keydb3 %REDIS1_ADDR% maxconn 20000 check inter 1s
              server keydb2 %REDIS2_ADDR% maxconn 20000 check inter 1s