简体   繁体   English

如何在 DataStax 中使用服务名称而不是 IP?

[英]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. 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.在本地尝试此操作时,我使用kubectl port-forward ,但是当我将服务上传到 Kubernetes 时,我想使用服务名称。 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当我添加 helm chart 安装后给我的链接时

Cassandra can be accessed through the following URLs from within the cluster: Cassandra 可以通过集群内的以下 URL 访问:

  • CQL: service-name.some-namespace.svc.cluster.local:9042 CQL:服务名称.some-namespace.svc.cluster.local:9042

I'm unable to connect, I'm getting a Cassandra.NoHostAvailableException and I have to use an IP.我无法连接,我得到一个Cassandra.NoHostAvailableException并且我必须使用 IP。

How to solve this problem.如何解决这个问题呢。 The IP changes every time I redeploy.每次我重新部署时,IP 都会发生变化。 How can I use the name instead of the IP?如何使用名称代替 IP?

Apparently, providing the DNS with format "DNS:PORT" as a parameter for AddContactPoint was not working.显然,为 DNS 提供格式为“DNS:PORT”的 AddContactPoint 参数不起作用。 Using the method WithPort did the trick.使用 WithPort 方法成功了。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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