Expose cockroach multi region database to public

Hello,

I am new to cockroach db. I just wanted to know some of the information about cockroach db multi cluster deployment.

I have deployed some of my web applications in GKE. I have used Kubernetes federation for app latency purpose. one cluster is deployed in Europe and other is deployed in asia region. and my application works fine.

I want cockroach db setup in same region. i have created 2 clusters in the Europe and Asia region and deployed cockroach db into that.

Now my question starts from here. How can i connect cockroach db to my application using IP. how can i expose cockroach db to access in my applications. I don’t want port forwarding because my application are deployed in different clusters.

i have .env file in my web app. content is below.

DB_IP : cockroach db ip [`how can i expose it ?`]
DB_PASSWORD : 
DB_USER : 
DB_PORT : 

I will be waiting for the positive reply on that. Thank you !

Hey @shivraj

Please feel free to review the examples of different apps in our documentation here. These are guides that demonstrate how to create a simple app in different languages, and make those apps work with CockroachDB. This should give you a firm base for how to configure your web app to utilize CockroachDB.

Let me know if there are any other questions.

Cheers,
Ricardo

2 Likes

@rickrock, Yes, I have check that documentation, But my concern is How can i expose the ip while db running on multi region cluster.

in the documentation they put the localhost as db host. But i need to connect database from different cluster and application. How can i create a public ip to connect db from different clusters. As i can’t use localhost.

I have already running single region cockroach cluster on kubernetes, and i have expose the service to the load balancer and i am using that LB ip from my application.

postgresql://my-user:mypassword@DB-ip:26257/DB-name?sslmode=require

Where DB-ip is load balancer ip, which i am using.

I want same setup in multi region for expose to the ip which i can access to the multiple applications.

I hope you understand my question.

Hey @shivraj

That’s a great question to a really interesting scenario. Usually, we find that its best to utilize multiple load balancers for multiple regions, and having connection strings going to each load balancer. The logic needs to be built into the app, in order to realize what region the user of the app is located in, in order to facilitate the correct load balancer connection string. That way, you can make due with lower latencies from the closet available region.

We touch on this scenario a bit more in our documentation here. We also go into a bit more specifics with using k8s, a Python app, and Cockroach Cloud, which is also described in the docs here.

Have a look through that info, and let me know if theres any other questions.

1 Like

@rickrock I am still thinking that how i can connect 2 lb in my app env file. My .env file look like below.

ENV=prod

# Database credentials
DB_USER=upm
DB_HOST=`LB-ip`
DB_NAME=`database-name`
DB_PORT=`26257`
DB_PASSWORD=`my-password`
DB_SSL_MODE=require

Suppose i create Database across 3 region Asia, Europe and US. Then i will have to create 3 Load balancer in each region right ?

My question is if i used Multi region cockroach db database across regions then what LB ip should i use in DB_HOST= ?

Hey @shivraj

That is correct, that 3 load balancers would be needed currently for the three regions,

I would recommend that there should be some logic in your app that can determine what region your user is currently coming from. With that information available, it’s a fairly straightforward process of using the closest load balancer to that user, in order to minimize latencies for that user’s experience. Once it’s determined, the IP can be assigned for that connection and propagated in your file.

Cheers,
Ricardo

1 Like