Kong is an open-source management layer for APIs, delivering high-performance and reliability (see getkong.org). Kong requires Cassandra as it's data store. As such, Instaclustr is a great way to run Cassandra for your Kong deployment. This article describes how to get set up to use Instaclustr with Kong.
Firstly, for a product installation or one where you will be doing any kind of performance/load testing, we highly recommend that your server running Kong is in the same AWS region or Azure Data Center as your Cassandra cluster. We support all AWS regions and most Azure Data Centers.
These are the steps to configure Kong to work with Instaclustr:
- Provision a new cluster on Instaclustr by logging in to the dashboard and choosing “Create Cassandra Cluster …”.
- Choose the same AWS region or Azure data centre as your Kong server.
- At the time of writing, Kong does not support user authentication or client connection encryption, so ensure that you turn these options off. You will need to rely on the firewall rules to limit access to the cluster to your server only. (Alternatively, on AWS you could use VPC peering.) Kong v0.4.2 has included support for authentication and encryption. You can therefore now enable these options in your cluster if desired - username, password and certificate file will have to be set in your kong configuration file. Also, if you use encryption, we recommend using Datastax DevCenter rather then CQLSH to connect to your cluster.
- All other settings can be left at default.
- Ensure the server from which you are running Kong is whitelisted in your cluster firewall rules.
- From the cluster page in the Instaclustr dashboard, choose Manage Cluster / Firewall Rules.
- In the Allowed Addresses box, enter the IP of your Kong host and click on "Save Cluster Settings".
- Navigate to the Cluster Details page for your cluster and note the Public IPs of the nodes that have been provisioned.
- Log in to a shell on your Kong host and, if necessary, install Kong according to the instructions on getkong.org.
- Optionally, install CQLSH on your Kong host and check the connection.
- pip install cqlsh is the easiest way to install cqlsh where you have pip installed.
- The run cqlsh x.x.x.x where x.x.x.x is the public IP of one of the nodes in your cluster (from step 3).
- cqlsh should connect and you should get a cqlsh> prompt. You can run describe keyspaces; to check that the connection is working. Then exit to quit cqlsh.
- Configure Kong:
- If necessary, copy the default konq.yml file to /etc/kong (you may need to create the directory first.)
cp /usr/local/lib/luarocks/rocks/kong/0.3.1-1/conf/kong.yml /etc/kong
- Open /etc/kong/kong.yml in your favourite text editor.
- Find the hosts: property under cassandra: and change it to look like the following:
- For Kong 0.4.2 and later this needs to look like:
- Start Kong and test:
- Run kong start
- Configure an API and run some transactions following instructions in the Kong docs quick start (http://getkong.org/docs/0.3.2/getting-started/quickstart/)
- Optionally Connect via cqlsh and view some of the data created:
- Run cqlsh x.x.x.x where x.x.x.x is the public IP of one of the nodes in your cluster (from step 3).
- From the cqlsh> prompt run use kong; to use the kong keyspace.
- Run select * from apis;