Easily Deploy and Scale RethinkDB With Docker and Kontena
If you're using the open source RethinkDB, this article will cover how you can quickly both get it up and running and scale it when things get busy.
Join the DZone community and get the full member experience.
Join For FreeRethinkDB is an open source, NoSQL, distributed document-oriented database. It stores JSON documents with dynamic schemas and is designed to facilitate pushing real-time updates for query results to applications. RethinkDB’s real-time push architecture dramatically reduces the time and effort necessary to build scalable real-time apps.
Kontena provides an easy solution to run and scale containerized applications — all batteries included. Thus, deploying RethinkDB with Kontena is super easy and simple. Today, we'll show you how to deploy a RethinkDB cluster and scale it up.
After we have set up Kontena, we can define RethinkDB in kontena.yml. This is very similar to how we can run RethinkDB locally with Docker Compose, but now we will deploy it to remote host nodes:
version: '2'
services:
db:
image: rethinkdb:latest
command: rethinkdb --bind all --join ${project}-db-1.kontena.local:29015
stateful: true
However, at this time, we are overriding the default command from Docker image and defining all database instances to join the cluster's first instance: command: rethinkdb --bind all --join ${project}-db-1.kontena.local:29015
Also, with Kontena, we can define the service as stateful, then data are persisted to the host node automatically. Also, notice that we don’t publish any ports publicly because all the services within the grid can connect to the database with Kontena’s internal DNS address.
As you can see the configuration is very simple and we can deploy a RethinkDB instance:
$ kontena app deploy db
After the deployment is finished we can open the RethinkDB’s admin UI with Kontena’s built-in VPN Access:
Now, we have one RethinkDB instance up and running. To scale the database up, we just fire the $ kontena app scale db 3
command. Because we defined the --join
option in kontena.yml
all the new database instances will join the cluster automatically.
Now we have all three RethinkDB instances up, so we can connect our application to the database. Our example application is a simple Ruby Sinatra application that is using the nobrainer gem for easy RethinkDB access:
app:
image: kontena/todo-rethinkdb-example:latest
instances: 3
environment:
- RETHINKDB_URL=rethinkdb://${project}-db/todo_production
- KONTENA_LB_VIRTUAL_PATH=/
- KONTENA_LB_INTERNAL_PORT=9292
command: bundle exec puma -p 9292 -e production
deploy:
wait_for_port: 9292
links:
- loadbalancer
loadbalancer:
image: kontena/lb:latest
deploy:
strategy: daemon
ports:
- 80:80
We can pass the RethinkDB address via environment variables to our application. In this case, we are also using the Kontena Load Balancer to route traffic between application instances.
We can deploy these services with $ kontena app deploy loadbalancer app
. (In this example, we are doing deployments separately for the DB and app services, but normally, they are deployed in one fell swoop with $ kontena app deploy
).
After the deployment is finished, we can open the web application in a browser and start using it:
We can configure sharding and replication for the RethinkDB table in the RethinkDB Admin UI:
As we can see, RethinkDB is very easy setup with the official Docker image. Kontena is a perfect fit for it by providing easy deployment and a scaling mechanism, and as a bonus, it offers the secure Admin UI access.
Published at DZone with permission of Lauri Nevala, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Send Email Using Spring Boot (SMTP Integration)
-
Health Check Response Format for HTTP APIs
-
4 Expert Tips for High Availability and Disaster Recovery of Your Cloud Deployment
-
Database Integration Tests With Spring Boot and Testcontainers
Comments