Deploying Couchbase has never been easier than before by using Ansible. I’ve written an Ansible role for deploying a dockerized Couchbase.
There are many reasons why you would want to deploy Couchbase as a Docker container. First of all, it is extremely easy, and OS independent. Second of all, as long as you persist the data by mapping a volume, then it is super easy to upgrade and downgrade versions. Simply update the version of the container. Finally, it is possible to make the container restart if there would be a crash. There are, of course, more advantages to running Couchbase in a container, but let’s not dive too deep in on that.
So, even though, it is easy to simply spin up a container, there is still some configuration that has to be done both on the host, and on the container. And this is what my Couchbase Ansible Role aims to solve.
What does it do?
Firstly, there are a lot of ports which has to be exposed for node-to-node communication and this is taken care of for you by the role.
Secondly, there is a couple of configurations that should be done on OS level on the host machine. Couchbase recommends disabling transparent huge pages, as well as, changing the swappiness. There are also some other improvements that can be done. And isn’t it nice to have this taken care of for you so that you don’t have to learn all this configuration?
Lastly, if you simply spin up Couchbase in a container, you will not have the data persisted if the container is stopped or rebooted. The role will map a volume by default to /opt/couchbase/var which is configurable with the Ansible variable couchbase_docker_volume_dir property.
Requirements
It is required that Docker is deployed on the host prior to the Couchbase Ansible Role is ran. I recommend adding the Ansible role geerlingguy.docker in your playbook prior to the Couchbase Ansible Role, which is a well tested and often used role for installing Docker on many different Linux distributions.
Getting started
The Couchbase Ansible Role is named snieking.couchbase_dockerized and can be found on Ansible Galaxy. It is a completely open source project, and you can view everything that the role does on my GitHub repository.
ansible-galaxy install snieking.couchbase_dockerized
Example playbook
- hosts: servers
roles:
- role: geerlingguy.docker
become: yes
- role: snieking.couchbase_dockerized
couchbase_version: enterprise-5.1.1
couchbase_docker_volume_dir: /home/snieking/couchbase/var
In the playbook above, I ensure that Docker is installed on the servers prior to running the role. I also override the Couchbase Version to 5.1.1, instead of the default value 5.5.2. Finally, I also override the mounted directory on the host machine. Typically this won’t be needed, but it is just to show that it is possible.