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

Classic environment
services:
  - id: redis1
    name: Redis Node 1
    dockerConfiguration:
      image: eqalpha/keydb
      imageVersion: alpine_x86_64_v6.3.4
      args: 
        - keydb-server 
        - --active-replica yes
        - --multi-master yes 
        - --replicaof 127.0.0.1 6382
    countMin: 1
    countMax: 1
    cpuLimit: 512 # MHz
    memoryLimitMiB: 128
    ports:
      - listeningPort: 6379
    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: alpine_x86_64_v6.3.4
      args: 
        - keydb-server
        - --active-replica yes
        - --multi-master yes
        - --replicaof 127.0.0.1 6381
    countMin: 1
    countMax: 1
    cpuLimit: 512 # MHz
    memoryLimitMiB: 128
    ports:
      - listeningPort: 6379
    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
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
Kubernetes environment
services:
  - id: redis1
    name: Redis Node 1
    dockerConfiguration:
      image: eqalpha/keydb
      imageVersion: alpine_x86_64_v6.3.4
      args: 
        - keydb-server 
        - --active-replica yes
        - --multi-master yes 
        - --replicaof $(REDIS2_HOST) 6379
    countMin: 1
    countMax: 1
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 128
    ports:
      - listeningPort: 6379
    links:
      - toServiceId: redis2
        toServicePort: 6379
        variableHost: REDIS2_HOST
        variablePort: REDIS2_PORT
        variableAddress: REDIS2_ADDR
  - id: redis2
    name: Redis Node 2
    dockerConfiguration:
      image: eqalpha/keydb
      imageVersion: alpine_x86_64_v6.3.4
      args: 
        - keydb-server
        - --active-replica yes
        - --multi-master yes
        - --replicaof $(REDIS1_HOST) 6379
    countMin: 1
    countMax: 1
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 128
    ports:
      - listeningPort: 6379
    links:
      - toServiceId: redis1
        toServicePort: 6379
        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
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
Be careful! In production, you probably don't want to expose your insecure Redis Insight to the public.
For Kubernetes environment: From Redis Insight, you can add new database manually. Redis 1 is reachable with redis1.<environment uuid>.svc.cluster.local (e.g.: redis1.06b4f97b-e4b4-416c-8f4a-a1e73cbffb7a.svc.cluster.local) and Redis 2 is reachable with redis2.<environment uuid>.svc.cluster.local.

2. Create KeyDB load balancer

Kubernetes environment
services:
  - id: redislb
    name: Redis LB
    dockerConfiguration:
      image: haproxy
      imageVersion: latest
    ports:
      - listeningPort: 6380
    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
        perms: "644"
        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
Kubernetes environment
services:
  - id: redislb
    name: Redis LB
    dockerConfiguration:
      image: haproxy
      imageVersion: latest
    ports:
      - listeningPort: 6380
    links:
      - toServiceId: redis1
        toServicePort: 6379
        variableHost: REDIS1_HOST
        variablePort: REDIS1_PORT
        variableAddress: REDIS1_ADDR
      - toServiceId: redis2
        toServicePort: 6379
        variableHost: REDIS2_HOST
        variablePort: REDIS2_PORT
        variableAddress: REDIS2_ADDR
    countMin: 2
    countMax: 2
    files:
      - path: /usr/local/etc/haproxy/haproxy.cfg
        interpolate: true
        perms: "644"
        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