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



使用数据税C#驱动程序我正在尝试连接到Cassandra,该Cassandra已使用Bitnami helm图表部署到Azure Kubernetes Services。

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

当在本地尝试时,我使用kubectl port-forward,但当我将服务上传到Kubernetes时,我想使用服务名称。同事们向我展示的许多应用程序都使用了这一点。当我在安装后添加舵图给我的链接时

Cassandra可以通过集群内的以下URL访问:

  • CQL:服务名称。一些命名空间。svc。集群。本地:9042

我无法连接,我收到了Cassandra.NoHostAvailableException,我必须使用IP。

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

显然,为DNS提供了格式"DNS:PORT";作为AddContactPoint的参数不起作用。使用WithPort方法达到了目的。

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

最新更新