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

How to use service name in DataStax and not IP?

使用 Datastax C# 驱动程序 我正在尝试连接到使用 Bitnami helm chart 部署到 Azure Kubernetes 服务的 Cassandra。

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

在本地尝试时,我使用 kubectl port-forward,但是当我将服务上传到 Kubernetes 时,我想使用服务名称。同事向我展示的许多应用程序都使用了它。当我添加 helm chart 安装后给我的 link

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

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

我无法连接,我得到一个 Cassandra.NoHostAvailableException,我必须使用一个 IP。

如何解决这个问题。每次重新部署时 IP 都会更改。 如何使用名称而不是 IP?

显然,提供格式为“DNS:PORT”的 DNS 作为 AddContactPoint 的参数无效。使用方法 WithPort 成功了。

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