Expose cockroach multi region database to public


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 ?`]

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.



@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.


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.


# Database credentials

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.


1 Like

Hey @rickrock Thank you so much for the clarification. I have exposed cockroach service to the network [regional] load balancer on GCP right now, But I have a question about load balancer service. Can i expose cockroach db service to the global load balancer on GCP ?

Hey @shivraj

I suspect that a better option may be to use the global load balancer to pass regional traffic to that appropriate region’s load balancer, who can then take that to an available CRDB node. Let me know if you have any other questions,


@rickrock What are the best practice to expose cockroach db in multi region. I am having same issues, My front end apps are in Asia & US region and also DBs are in same region. Is there any documentation for Kubernetes multi region database expose to access better way ?

Hey @vishal

I sort of mentioned what may be your best bet previously. Basically, having a global load balancer that can recognize the location of the request, and then pass that request on to the regional load balancer closest to the source. That regional load balancer then can pass the request on to the next available node, which should be able to handle the request.

I hope that answers your question, let me know if there is any other questions.


@rickrock, I understand what you are suggested. Is it possible to setup Multi region database behind global load balancer. I want to create single global Load balancer and If request come from Europe region on global LB then request will forward to the europe DB and if request comes from Asia then that LB will forward traffic to the asia DB ?

Is it possible ? If yes , Then is there any documentation or steps for the same ?