With Couchbase Capella, our fully hosted DBaaS, you can provision an entire Couchbase cluster in minutes. Without having to know anything about deploying Couchbase, you can have all of the infrastructure provisioned, configured, secured, and finally ready to use all without having to have specific expertise in those areas—this is revolutionary! Previously, these kinds of management tasks were undertaken by project teams and success was measured in weeks, all of which can now be carried out through a GUI in minutes.

We haven’t stopped at just building an easy to use GUI though, we have also released an API that can be used to provision clusters, for many different purposes. As great as GUIs are, you can’t beat having a script run in the background while you get on with your day, or read xkcd. 

In all seriousness, automating the provisioning of clusters saves a lot of time, in both transient cluster environments, and in use cases where multiple clusters need to be created, e.g.,  geo-distributed replication. The key here is also to help decrease toil, as per the SRE handbook, and this could be just the tip of the iceberg. 

Following on from automated provisioning you can start to configure clusters through APIs as well as scripted processes. One of the key tenets here with Capella is automating and utilizing the expertise of Couchbase, so that you can focus on delivering and meeting key business objectives – in sales speak, giving companies competitive advantage. 

To give you a taste of toil reduction and a tickle of what it would be like to spend time working on your business problems, rather than your database, I’ve created a Python script which will provision you a Cluster through our API, without any of that GUI interaction. The script uses the API helpers which Jon Giffard (Principal Product Manager of Capella) created, and will create a cluster based on a customisable configuration.

Setup Python & API keys

Within this repo, there is a README that explains the prerequisites and how to install the required Python libraries that are listed in requirements.txt. Providing your system meets the prerequisites, and you’ve installed the requirements, use the following documentation to generate API keys for your Capella tenant (the Org Owner role is needed to generate these keys).

Take the keys you have generated, either export the API keys as variables, or create an EnvVars.py file within the capellaAPI folder, as described in the README. You can test whether these steps have been successful by running:

Providing you get output similar to the following when running the getClouds.py test script, you have successfully setup your environment:

Couchbase Capella - basic cluster setup

Automating provisioning script

With your environment setup, it’s time to test our automation script. Within the python folder of the repo will be the automation.py file. This file takes just two arguments: a project name and a cluster name—the project has to have been created before running the script. 

While this is automating to an extent, there will be some initial setup required, once you’ve created the project you can create your clusters using the automation.py script. 

For example, if I’ve already created a project in my Capella tenant called sam-demo then I can create a cluster in that project with a name of otto like so: 

And what you should end up with is the following output (redacted for brevity):

I’ve removed some of the repeated checks, we should get an update every 5 seconds—feel free to edit the interval to meet your needs. This is likely an appropriate interval because it can take a couple of minutes to create a cluster. Checking more frequently would not add more information but anything slower may feel too slow.

So what exactly have we deployed?

I’ve provided a default configuration that meets the specification requirements of the Capella API. Let’s take a look at it in the createHostedClusterInProject.py file in the python folder:

 

What next?

This was just a sample test configuration but you can see that we’ve got the minimum spec for: node size (3), a single AZ, and all services. It doesn’t meet best practices but you would be able to start a cluster for testing code against.

We can connect our application to this cluster without having to go through the configuration GUI. All you would need to do is adjust the configuration to use your database users, whitelist your IP and connect your application.

I hope this prompts an awakening and an awareness of the art of the possible with our API. In the future, we’ll be adding more functionality to the API. When we do, I’ll be sure to share an example of running some regression tests against an automatically provisioned Couchbase Capella cluster.

Here are some of the resources mentioned in this post:

Author

Posted by Sam Redman, Solutions Engineer

Sam Redman is a Solutions Engineer at Couchbase. Sam previously worked in development and SRE environments before joining Couchbase.

Leave a reply