Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitnami/redis] use hostnames in sentinel #7428

Closed

Conversation

tomislater
Copy link
Contributor

@tomislater tomislater commented Sep 7, 2021

Description of the change

Because it is a chart for Kubernetes, we should use hostnames instead of IPs (https://redis.io/topics/sentinel#ip-addresses-and-dns-names). I added more information about my case in #1682 and #5418.

Benefits

It should works better in dynamic environment.

Possible drawbacks

I don't know yet. Maybe there is a bug somewhere. I have tested on my clusters and everything works correctly. But still...

Applicable issues

Checklist

  • Chart version bumped in Chart.yaml according to semver.
  • Variables are documented in the README.md
  • Title of the PR starts with chart name (e.g. [bitnami/<name_of_the_chart>])

After this change sentinel.conf looks like:

cat opt/bitnami/redis-sentinel/etc/sentinel.conf
cat opt/bitnami/redis-sentinel/etc/sentinel.conf
dir "/tmp"
port 26379
sentinel monitor mymaster my-redis-node-1.my-redis-headless.my-redis.svc.cluster.local 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 18000

# User-supplied sentinel configuration:
sentinel resolve-hostnames yes
sentinel announce-hostnames yes
# End of sentinel configuration
sentinel myid 475427d0cefa44aff518ab6b888c3510314d882c
sentinel announce-ip "my-redis-node-1.my-redis-headless.my-redis.svc.cluster.local"

sentinel known-sentinel mymaster my-redis-node-2.my-redis-headless.my-redis.svc.cluster.local 26379 80d3b99129c4f9bb62cdcec2399499f2c4666789

sentinel known-replica mymaster my-redis-node-0.my-redis-headless.my-redis.svc.cluster.local 6379

sentinel known-sentinel mymaster my-redis-node-0.my-redis-headless.my-redis.svc.cluster.local 26379 cae9f9b5ed951299f4bdc7de1da8e996e7b7197c

sentinel known-replica mymaster my-redis-node-2.my-redis-headless.my-redis.svc.cluster.local 6379
# Generated by CONFIG REWRITE
protected-mode no
user default on nopass ~* &* +@all
sentinel config-epoch mymaster 1
sentinel leader-epoch mymaster 1
sentinel current-epoch 1

@tomislater
Copy link
Contributor Author

tomislater commented Sep 7, 2021

After deleting different pods x times (to force re-election and try to find potential bugs) :

cat opt/bitnami/redis-sentinel/etc/sentinel.conf
dir "/tmp"
port 26379
sentinel monitor mymaster my-redis-node-1.my-redis-headless.my-redis.svc.cluster.local 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 18000

# User-supplied sentinel configuration:
sentinel resolve-hostnames yes
sentinel announce-hostnames yes
# End of sentinel configuration
sentinel myid 80d3b99129c4f9bb62cdcec2399499f2c4666789
sentinel announce-ip "my-redis-node-2.my-redis-headless.my-redis.svc.cluster.local"

sentinel known-sentinel mymaster my-redis-node-0.my-redis-headless.my-redis.svc.cluster.local 26379 cae9f9b5ed951299f4bdc7de1da8e996e7b7197c

sentinel known-replica mymaster my-redis-node-0.my-redis-headless.my-redis.svc.cluster.local 6379

sentinel known-sentinel mymaster my-redis-node-1.my-redis-headless.my-redis.svc.cluster.local 26379 475427d0cefa44aff518ab6b888c3510314d882c

sentinel known-replica mymaster my-redis-node-2.my-redis-headless.my-redis.svc.cluster.local 6379
# Generated by CONFIG REWRITE
protected-mode no
user default on nopass ~* &* +@all
sentinel config-epoch mymaster 3
sentinel leader-epoch mymaster 3
sentinel current-epoch 4

@tomislater
Copy link
Contributor Author

I also tested it with haproxy as a "fronted" and this also works.

Copy link
Contributor

@juan131 juan131 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tomislater

Thanks so much for this great contribution!!!

I agree that we shouldn't be use IPs on a Kubernetes environment since they're ephemeral, and we should rely on stable network identifiers such as the hostname. Therefore, I'm fine with your approach.

I'd like @rafariossaa to double-check this, since he has more experience with Redis & Sentinel configuration. He's currently on PTO so please expect a few days delay before he comes back to you.

@github-actions
Copy link

This Pull Request has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thank you for your contribution.

@github-actions github-actions bot added the stale 15 days without activity label Sep 25, 2021
@tomislater
Copy link
Contributor Author

tomislater commented Sep 25, 2021

👋 what about this PR? It works on staging and prod since then and I don’t see any problems.

I had one problem because I had not changed masterSet (both deployments had the same masterSet) and two separated sentinels (in different namespaces) were thinking that they are one cluster 🤝, but it is another issue.

@github-actions github-actions bot removed the stale 15 days without activity label Sep 26, 2021
@juan131
Copy link
Contributor

juan131 commented Sep 27, 2021

Sorry @tomislater I lost the track of this one!! Please @rafariossaa take a look to this PR when possible.

@rafariossaa
Copy link
Contributor

Hi,
I am taking a look to it. For me it makes sense.
Please, allow me a couple of days to do some testing in my side before merging.

@tomislater
Copy link
Contributor Author

tomislater commented Sep 29, 2021

⚠️ Hmm, strange. I have two deployments (with sentinels) in different namespaces with different masterSets.
Sometimes, when I delete two pods at the same time (one in namspace A and one in namespace B) sentinel from namespace A thinks that replica from namespace B belongs to him. And vice cersa.

It is very hard to reproduce. Only twice I have seen this.

Maybe is it something wrong with announce-hostnames or replica-announce-ip 🤔

@rafariossaa
Copy link
Contributor

Hi,
In that case I will wait until this is clarified before merging it.

@tomislater
Copy link
Contributor Author

Yeah, please do not merge it. I see that there were some new changes on master.

@tomislater
Copy link
Contributor Author

tomislater commented Sep 30, 2021

Okay, my changes are not required anymore. We can close this PR. Similar changes have been added here: 722dead
15.4.0 uses hostnames instead of names.

But, I have noticed the same problems. Auto-discovery seems broken. I am going to create an issue for this.

@rafariossaa
Copy link
Contributor

Hi,
In that case I am closing it.
Thanks

@rafariossaa rafariossaa closed this Oct 1, 2021
@tomislater tomislater deleted the redis-sentinel-use-announce branch October 1, 2021 08:51
@vfiset
Copy link

vfiset commented Oct 18, 2021

Hi @tomislater could you please expand on what you've refered to as:

Auto-discovery seems broken

in your last comment?

I am still having some issues from time to time even when using the version containing #7461

thanks

@tomislater
Copy link
Contributor Author

tomislater commented Oct 19, 2021

I referred to this problem: #7428 (comment) but it was visible only on my branch. With current version everything works correctly.

https://github.com/bitnami/charts/tree/master/bitnami/redis#redis-sentinel-configuration-parameters remember about masterSet setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants