OT-CONTAINER-KIT / redis-operator

A golang based redis operator that will make/oversee Redis standalone/cluster/replication/sentinel mode setup on top of the Kubernetes.
https://ot-redis-operator.netlify.app/
Apache License 2.0
826 stars 229 forks source link

Enable DNS/hostnames support for sentinel #1054

Open AlievR opened 2 months ago

AlievR commented 2 months ago

Currently, sentinel selects a redis master based on the pod's IP address. I think this is not entirely correct; it would be more correct to use DNS names. I'm trying to do something like this:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: sentinel-config
data:
  redis-sentinel-additional.conf: |
    daemonize no
    pidfile "/var/run/redis-sentinel.pid"
    dir "/tmp"
    port 26379
    sentinel resolve-hostnames yes
    sentinel announce-hostnames yes
    sentinel monitor mymaster redis-replication-0.redis-replication-headless.redis-test.svc.cluster.local 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel failover-timeout mymaster 180000
    sentinel parallel-syncs mymaster 1
---
apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: RedisSentinel
metadata:
  name: redis-sentinel
spec:
  clusterSize: 3
  podSecurityContext:
    runAsUser: 1000
    fsGroup: 1000
  pdb:
    enabled: false
    minAvailable: 1
  redisSentinelConfig:
    redisReplicationName: redis-replication
    masterGroupName: "mymaster"
    redisPort:  "6379"
    quorum: "2"
    parallelSyncs: "1"
    failoverTimeout: "180000"
    downAfterMilliseconds: "30000"
    additionalSentinelConfig: sentinel-config
  kubernetesConfig:
    image: quay.io/opstree/redis-sentinel:v7.0.12
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 101m
        memory: 128Mi
      limits:
        cpu: 101m
        memory: 128Mi

As a result, sentinel crashes with the following error:

 *** FATAL CONFIG FILE ERROR (Redis 7.2.1) ***                                                                                                              │
│ Reading the configuration file, at line 7                                                                                                                  │
│ >>> 'sentinel monitor mymaster redis-replication-0.redis-replication-headless.redis-test.svc.cluster.local 6379 2'                                         │
│ Duplicate master name. 

It is also worth noting that in crd Redis Sentinel there is no way to upload volumes. I believe that it should generally be configured this way from the start. Please help in solving this problem

redis-operator version: 0.18.0

woodliu commented 2 months ago

@AlievR i think this operator not support this function, it just mount the senltinet config file to pod. To use DNS, it need to change the config file for both sentinel nodes and redis nodes to announce the hostname, check this: https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#ip-addresses-and-dns-names