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'  
    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:

  image: kontena/todo-rethinkdb-example:latest
  instances: 3
    - RETHINKDB_URL=rethinkdb://${project}-db/todo_production
  command: bundle exec puma -p 9292 -e production
    wait_for_port: 9292
    - loadbalancer

   image: kontena/lb:latest
     strategy: daemon
     - 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.