1

We are bringing up a Cassandra cluster, using k8ssandra helm chart, it exposes several services, our client applications are using the datastax Java-Driver and running at the same k8s cluster as the Cassandra cluster (this is testing phase)

CqlSessionBuilder builder = CqlSession.builder();

What is the recommended way to connect the application (via the Driver) to Cassandra?

Adding all nodes?

for (String node :nodes) {
   builder.addContactPoint(new InetSocketAddress(node, 9042));
}

Adding just the service address?

 builder.addContactPoint(new InetSocketAddress(service-dns-name , 9042))

Adding the service address as unresolved? (would that even work?)

 builder.addContactPoint(InetSocketAddress.createUnresolved(service-dns-name , 9042))
Doron Levi
  • 458
  • 4
  • 16

2 Answers2

1

The k8ssandra Helm chart deploys a CassandraDatacenter object and cass-operator in addition to a number of other resources. cass-operator is responsible for managing the CassandraDatacenter. It creates the StatefulSet(s) and creates several headless services including:

  • datacenter service
  • seeds service
  • all pods service

The seeds service only resolves to pods that are seeds. Its name is of the form <cluster-name>-seed-service. Because of the ephemeral nature of pods cass-operator may designate different C* nodes as seed nodes. Do not use the seed service for connecting client applications.

The all pods service resolves to all Cassandra pods, regardless of whether they are readiness. Its name is of the form <cluster-name>-<dc-name>-all-pods-service. This service is intended to facilitate with monitoring. Do not use the all pods service for connecting client applications.

The datacenter service resolves to ready pods. Its name is of the form <cluster-name>-<dc-name>-service This is the service that you should use for connecting client applications. Do not directly use pod IPs as they will change over time.

John Sanda
  • 86
  • 3
  • Thanks @John Sanda, that was very helpful! the issue is that the Driver API looks like this: addContactPoint(@NonNull InetSocketAddress contactPoint) The InetSocketAddress constructor resolves the address and takes the first IP: addr = InetAddress.getByName(hostname); So what is the use of using the service dns name if the resolve is done immediately? – Doron Levi Nov 30 '21 at 20:45
  • The point of using the service is that if the first contact point fails then you can try subsequent ones. – John Sanda Nov 30 '21 at 21:16
0

Adding all nodes?

You definitely do not need to add all of the nodes as contact points. Even in vanilla Cassandra, only adding a few is fine as the driver will gossip and find the rest.

Adding just the service address?

Your second option of binding on the service address is all you should need to do. The nice thing about the service address, is that it will account for changing/removing of IPs in the cluster.

Aaron
  • 55,518
  • 11
  • 116
  • 132
  • Thanks Aaron, as I wrote above, the issue with the driver API working with InetSocketAddress, is that this class constructor resolves immediately the service name to IP, taking only the first IP address – Doron Levi Nov 30 '21 at 21:06