<p>I have a Cassandra cluster running in Kubernetes on AWS (using the incubator Helm chart). When I expose the nodes with a load balancer, Datastax is unable to directly connect to the nodes in the way it wants because it tries to use the IPs internal to the Kubernetes network. But it can still successfully read and write through the loadbalancer. <a href="https://docs.datastax.com/en/dse-planning/doc/planning/planningAntiPatterns.html#planningAntiPatterns__AntiPatLoadBal" rel="nofollow noreferrer">This is not recommended however</a> so I am looking for a proper solution.</p>

<p>Is there a way to have datastax connect properly with this setup? Would it require changing the <code>cassandra.yaml</code> inside the container (yuck)?</p>

<p>First of all. You can't use LoadBalancer for this purpose.</p>

<p>Set up the service like so:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: cassandra
  name: cassandra
spec:
  type: NodePort
  ports:
  - port: 9042
    nodePort: 30042
  selector:
    app: cassandra
</code></pre>

<p>The nodePort will be available outside the Kubernetes cluster. The nodePort has to be between 30000-32767.</p>

<p>From datastax driver, connect to K8S_NODE_IP:NODEPORT (not the pod ip).</p>
