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

I have created rec service(statefulset) as mentioned in documentation. How to connect this rec using StackExchange.Redis #192

Open
course-git opened this issue Sep 8, 2021 · 8 comments

Comments

@course-git
Copy link

How to connect to cluster using stackexchange.redis
Do I need to create DB and connect to it. If so how can i do that

Is there any documentation around this?
I want to connect to this redis cluster from other apps running in the cluster.

@laurentdroin
Copy link
Contributor

Hi,

You will indeed need to create a database (managing Redis databases is the primary purpose of a Redis Enterprise cluster).
There are multiple ways to create databases, but in Kubernetes, the preferred way would be to create a RedisEnterpriseDatabase resource.

You can find an example here:
https://docs.redis.com/latest/platforms/kubernetes/concepts/db-controller/#creating-databases

Once the database is created, a k8s service will automatically be created for you and that service is what you would use to connect your client application to the database (just like you would use any k8s service).

Hops this helps.

Laurent.

@course-git
Copy link
Author

hi @laurentdroin
so I connect using **db-headless service?

Though i was not successfull to connect using redisInsight (i tried port-forwarding my headless service and try connecting in RedisInsight)

@laurentdroin
Copy link
Contributor

Hi,

Yes, you called the database "db", you should see two services, "db-headless" and "db". You can use either (one is a ClusterIP service and goes through an internal k8s Load Balancer, the other binds directly to the relevant pods, and so choose what you prefer, even if the database secret, IIR, lists the headless service).

Port-forwarding should work.
Can you share

  • the output of kubectl get svc
  • the port-forward command you used?
  • a screenshot showing how the connection information was entered in RedisInsight?

Laurent.

@course-git
Copy link
Author

hi @laurentdroin

i port forwarded mine *db-headless service, and indeed was able to connect using RedisInsight.
But not able to connect using Stackexchange.Redis in my application
Getting this error:-

It was not possible to connect to the redis server(s). There was an authentication failure; check that passwords (or client certificates) are configured correctly. UnableToConnect on passwordHash:6379/Interactive,


I used following command after port forwarding db-headless service to 8082 port(kubectl port-forward svc/db-headless 8082:12409) :-
ConnectionMultiplexer.Connect("localhost:8082, passwordHash");

image

@laurentdroin
Copy link
Contributor

Hi,

I am not familiar with Stackexchange.Redis and you might need to contact Redis Enterprise support if we cannot resolve this but just looking at the Stackexchange.Redis documentation, the code sample you posted here seems to match this documented scenario:

A more complicated scenario might involve a master/replica setup; for this usage, simply specify all the desired nodes that make up that logical redis tier (it will automatically identify the master):

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("server1:6379,server2:6379");

Because you have localhost:8082, passwordHash within a "double-quote" pair, it's possible that it considers that your password is actually the name of second Redis server, and because there is no port number for it, the default 6379 is taken.

It then would be logical to get the UnableToConnect on passwordHash:6379 error.

So overall, it would seem to me that you need to find a way to specify the password. I did a quick search and I think the following might help you:
https://stackoverflow.com/questions/23923247/password-for-redis-with-stackexchange-redis

Cheers,

Laurent.

@course-git
Copy link
Author

Thank you @laurentdroin , This was helpful

Mine last question regarding REDB :- Is there a way to specify dedicated port(and hostname) for my redb service?

@laurentdroin
Copy link
Contributor

Hi,

It is not possible to specify the database port in the REDB manifest at the moment (although this has been requested, so it is possible that such a feature will be implemented in a future version).
As for the hostname, it is based on the REDB name (and the namespace name), so you have some control over it. By default, two services are created for each Redis Enterprise database. A ClusterIP service that has the same name as the REDB, and a headless service that has the same name, only with the "-headless" suffix. The hostname to use is the name of the service you want to use (you can use either, depending on whether you want to connect through a k8s load balancer or directly to the relevant pods).
Assuming that you have created a database called "mydb" in the namespace "myns", and that you will use the ClusterIP service, the hostname to connect to the database from within the "myns" namespace will simply be "mydb" (it can also be "mydb.myns" or "mydb.myns.svc" or "mydb.myns.svc.cluster.local").
If you connect to the database from a different namespace, you will need to use "mydb.myns" (it can also be "mydb.myns.svc" or "mydb.myns.svc.cluster.local").

I hope this helps,

Laurent.

@laurentdroin
Copy link
Contributor

Hi,

Following up on this. The latest release (6.2.8-2) now allows specifying the database port in the REDB manifest via the databasePort property.

Cheers,

Laurent.

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

No branches or pull requests

2 participants