<p>I have a 3 Node cluster running on GCP in Kubernetes. I am able to forward the port and connect with my DB Tool to the cluster:</p>

<pre><code>$ kubectl port-forward elassandra-0 9042
</code></pre>

<p>When I try to connect to the cassandra cluster from my Spring Boot application, I get the following error:</p>

<pre><code>2018-11-14 17:43:36,339 INFO  [5914] [localhost-startStop-1] c.d.d.c.Cluster [Cluster.java:1587] New Cassandra host /10.4.3.3:9042 added
2018-11-14 17:43:36,339 INFO  [5914] [localhost-startStop-1] c.d.d.c.Cluster [Cluster.java:1587] New Cassandra host /10.4.2.4:9042 added
2018-11-14 17:43:36,340 INFO  [5915] [localhost-startStop-1] c.d.d.c.Cluster [Cluster.java:1587] New Cassandra host /127.0.0.1:9042 added
2018-11-14 17:43:41,391 WARN  [10966] [cluster1-nio-worker-2] c.d.d.c.HostConnectionPool [HostConnectionPool.java:184] Error creating connection to /10.4.2.4:9042

com.datastax.driver.core.exceptions.TransportException: [/10.4.2.4:9042] Cannot connect
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:167)
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:150)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:504)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:483)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121)
</code></pre>

<p>I am trying to connect to <code>127.0.0.1:9042</code>, the other hosts are being pulled from the cluster by the spring-data framework.</p>

<p>What am I doing wrong here?</p>

<p>Thanks.</p>

Alex Tbk
<p>Answering own question:</p>

<p>You need to specify custom adress resolution driver side as described here:</p>

<p><a href="https://docs.datastax.com/en/developer/java-driver/2.1/manual/address_resolution/" rel="nofollow noreferrer">https://docs.datastax.com/en/developer/java-driver/2.1/manual/address_resolution/</a></p>

<p>In detail when you want to use only one node:</p>

<pre><code>public class MyAdressTranslator implements AddressTranslator {
    @Override
    public void init(Cluster cluster) {}

    public InetSocketAddress translate(InetSocketAddress address) {
        return new InetSocketAddress("127.0.0.1", 9042);
    }

    @Override
    public void close() {}
}
</code></pre>
