简体   繁体   中英

How to use service name in DataStax and not IP?

Using the Datastax C# Driver I'm trying to connect to Cassandra which was deployed to Azure Kubernetes Services using a Bitnami helm chart.

var cluster = Cluster.Builder()
   .AddContactPoint("127.0.0.0") // example IP
   .WithCredentials("cassie", "some-pass")
   .Build();

When trying this locally I use kubectl port-forward , but when I'm uploading my service to Kubernetes I want to use service name. Many applications shown to me by colleagues use just that. When I add the link that helm chart gives to me after I install it

Cassandra can be accessed through the following URLs from within the cluster:

  • CQL: service-name.some-namespace.svc.cluster.local:9042

I'm unable to connect, I'm getting a Cassandra.NoHostAvailableException and I have to use an IP.

How to solve this problem. The IP changes every time I redeploy. How can I use the name instead of the IP?

Apparently, providing the DNS with format "DNS:PORT" as a parameter for AddContactPoint was not working. Using the method WithPort did the trick.

var cluster = Cluster.Builder()
   .WithPort(PORT)
   .AddContactPoint("dns")
   .WithCredentials("cassie", "some-pass")
   .Build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM