OT-CONTAINER-KIT / redis

A production optimized redis docker image
https://opstree.github.io
23 stars 51 forks source link

Update entrypoint-sentinel.sh #73

Closed iva3682 closed 2 months ago

iva3682 commented 9 months ago

add SENTINEL_ID for fixed sentinel myid

drivebyer commented 2 months ago

Why do we need custom this param ? @iva3682

iva3682 commented 2 months ago

When you restart a pod with Sentinel, its myid changes to a random one. Other Sentinels receive his new myid, but the old one also takes part in the elections, which prevents the correct determination of the Sentinel master. Using the SENTINEL_ID parameter, you can fix myid to a specific value. For example, (when using Stateful Sets) like this:

...
- env:
  - name: SENTINEL_ID
    valueFrom:
      fieldRef:
    apiVersion: v1
    fieldPath: metadata.name
...
drivebyer commented 2 months ago

I understand. It seems to be related to removing the sentinel in the cluster, as described in this Redis documentation. I'm not sure if it works, because I couldn't find an example of sentinel myid in the Redis GitHub repository.

iva3682 commented 2 months ago

Yes, for some reason Redis developers do not mention the possible "sentinel myid" configuration in sentinel.conf (it might make sense to create a corresponding issue in the redis repository), but this parameter is described here: https://github.com/redis/redis/blob/617909e943be0691ac9179aa1e6664937a4ca255/src/sentinel.c#L510. I use this patch in my cluster and it works fine: after restarting the Sentinel pod, the expected number of instances participate in the elections, not +1. There is no need to execute the SENTINEL RESET command after restarting the pod, this has a good effect on the autonomy of the Sentinel cluster.

drivebyer commented 2 months ago

Please fix https://github.com/OT-CONTAINER-KIT/redis/pull/73/checks?check_run_id=21976287248