# Failed to Connect Scylladb From Scala, while Scylladb Nodes are Running in Kubernetes

**URL:** <https://forum.scylladb.com/t/failed-to-connect-scylladb-from-scala-while-scylladb-nodes-are-running-in-kubernetes/1466>\
**Category:** ScyllaDB\
**Tags:** kubernetes, scala\
**Created:** [April 7, 2024, 9:23am UTC](https://forum.scylladb.com/t/failed-to-connect-scylladb-from-scala-while-scylladb-nodes-are-running-in-kubernetes/1466 "2024-04-07T09:23:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaryab\_Ali1](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/zaryab_ali1/32/756_2.png) [@Zaryab\_Ali1](https://forum.scylladb.com/u/Zaryab_Ali1)\
**Post date:** [April 7, 2024, 9:23am UTC](https://forum.scylladb.com/t/failed-to-connect-scylladb-from-scala-while-scylladb-nodes-are-running-in-kubernetes/1466/1 "2024-04-07T09:23:38Z")

</div>

I’m trying to run Scylladb Nodes in k8s and access them from Scala (Phantom Library).

**Kubernetes**

Firstly I’ve followed commands from official scylladb documentation to create scylladb cluster.

```auto
$ minikube start --cpus=6
$ eval $(minikube docker-env)
$ git clone https://github.com/scylladb/scylla-operator.git
$ cd scylla-operator
$ kubectl apply -f examples/common/cert-manager.yaml
$ kubectl wait --for condition=established crd/certificates.cert-manager.io crd/issuers.cert-manager.io
$ kubectl -n cert-manager rollout status deployment.apps/cert-manager-webhook
$ kubectl apply -f deploy/operator.yaml
$ kubectl wait --for condition=established crd/scyllaclusters.scylla.scylladb.com
$ kubectl -n scylla-operator rollout status deployment.apps/scylla-operator
$ kubectl create -f examples/generic/cluster.yaml

```

After all above commands scylladb cluster got ready, I’ve checked using some commands:

```auto
$ kubectl -n scylla get pods
NAME READY STATUS RESTARTS AGE
simple-cluster-us-east-1-us-east-1a-0 2/2 Running 0 90m
simple-cluster-us-east-1-us-east-1a-1 2/2 Running 0 80m
simple-cluster-us-east-1-us-east-1a-2 0/2 Pending 0 77m

$ kubectl -n scylla get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
simple-cluster-client ClusterIP 10.98.139.252 <none> 7000/TCP,7001/TCP,9042/TCP,9142/TCP,19042/TCP,19142/TCP,7199/TCP,10001/TCP,9180/TCP,5090/TCP,9100/TCP,9160/TCP 90m
simple-cluster-us-east-1-us-east-1a-0 ClusterIP 10.98.37.120 <none> 7000/TCP,7001/TCP,9042/TCP,9142/TCP,19042/TCP,19142/TCP,7199/TCP,10001/TCP,9180/TCP,5090/TCP,9100/TCP,9160/TCP 90m
simple-cluster-us-east-1-us-east-1a-1 ClusterIP 10.105.171.34 <none> 7000/TCP,7001/TCP,9042/TCP,9142/TCP,19042/TCP,19142/TCP,7199/TCP,10001/TCP,9180/TCP,5090/TCP,9100/TCP,9160/TCP 90m
simple-cluster-us-east-1-us-east-1a-2 ClusterIP 10.110.32.166 <none> 7000/TCP,7001/TCP,9042/TCP,9142/TCP,19042/TCP,19142/TCP,7199/TCP,10001/TCP,9180/TCP,5090/TCP,9100/TCP,9160/TCP 90m

$ kubectl exec -n scylla -it simple-cluster-us-east-1-us-east-1a-0 -- nodetool status
Defaulted container "scylla" out of: scylla, scylla-manager-agent, sidecar-injection (init)
Datacenter: us-east-1
=====================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns Host ID Rack
UN 10.98.37.120 108.99 KB 256 ? a1d76285-964f-48b1-b87d-2e2fafa96877 us-east-1a
UN 10.105.171.34 201.48 KB 256 ? c2204fec-b713-4fd5-ba47-d8b72505ac12 us-east-1a

Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless

```

After setting above scylladb cluster, now I need to access it via my scala code.

**Scala**

schema.scala:

```auto
abstract class MyDataSchema extends Table[MyDataSchema, MyData] {

  override def tableName: String = "mydata"

  object myColumn extends OptionalStringColumn with PartitionKey {
    override def name: String = "myColumn"
  }
}

```

connection.scala:

```auto
class ScyllaDBConnection extends ScyllaDBConnectionTrait {

  override def connectionProvider: CassandraConnection = {
    val applicationConf: Config = ConfigFactory.load("application.conf")
    val keyspace: String = applicationConf.getString("keyspace.keyspaceName")
    val connection: CassandraConnection =
      ContactPoints(List("10.98.139.252")) //10.98.139.252 is IP of Service
        .keySpace(keyspace)
    connection
  }

}

```

database.scala:

```auto
class MyDB(override val connector: CassandraConnection)
  extends Database[MyDB](connector) {
  object MyData extends MyDataSchema with Connector
}

```

Now the problem is whenever I run this, it gives an error:

```auto
All host(s) tried for query failed (tried: /10.98.139.252 (com.datastax.driver.core.exceptions.TransportException: [/10.98.139.252] Cannot connect))

```

I’ve tried different things in:

connection.scala:

```auto
class ScyllaDBConnection extends ScyllaDBConnectionTrait {

  override def connectionProvider: CassandraConnection = {
    val applicationConf: Config = ConfigFactory.load("application.conf")
    val keyspace: String = applicationConf.getString("keyspace.keyspaceName")
    val connection: CassandraConnection =
      ContactPoints(List("10.98.139.252")) //10.98.139.252 is IP of Service
        .keySpace(keyspace)
    connection
  }

}

```

I’ve tried to give pod IP, service IP, scylladb node IP and service name to connect ContactPoints but nothing worked for me.

Guide me how can I connect my above scala service with Scylladb Cluster which is running on Kubernetes.

---

<div class="post-metadata">

**Author:** ![zimnx](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/zimnx/32/150_2.png) [@zimnx](https://forum.scylladb.com/u/zimnx)\
**Post date:** [May 8, 2024, 6:47am UTC](https://forum.scylladb.com/t/failed-to-connect-scylladb-from-scala-while-scylladb-nodes-are-running-in-kubernetes/1466/2 "2024-05-08T06:47:01Z")

</div>

I guess you don’t have connectivity to Kubernetes Pods/Services from machine where you run your Scala code.  
Either set up this connectivity (check minikube documentation), or run your code as a Pod in your Kube cluster.
