Using Instaclustr with Kong

Kong is an open-source management layer for APIs, delivering high-performance and reliability (see http://getkong.org). Kong requires Cassandra as its 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 region as your Cassandra cluster. We support all AWS regions, most Azure Data Centers, Google Cloud Platform, and Softlayer.

These are the steps to configure Kong to work with Instaclustr:

  1. Provision a new cluster on Instaclustr by logging into the dashboard and choosing “Create Cassandra Cluster …”.
    1. Choose the same region as your Kong server. 
    2. Before v0.4.2, 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.)

      Picture1_pix.png

      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.
    3. All other settings can be left at default.
  2. Ensure the server from which you are running Kong is whitelisted in your cluster firewall rules.
    1. From the cluster page in the Instaclustr dashboard, choose Manage Cluster / Firewall Rules.
    2. In the Allowed Addresses box, enter the IP of your Kong host and click on "Save Cluster Settings".
  3. Navigate to the Cluster Details page for your cluster and note the Public IPs of the nodes that have been provisioned.

    public_address.png

  4. Log in to a shell on your Kong host and, if necessary, install Kong according to the instructions on getkong.org.
  5. Optionally, install CQLSH on your Kong host and check the connection.
    1. Run:
      pip install cqlsh
      It is the easiest way to install cqlsh where you have pip installed.
    2. 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).
    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.
  6. Configure Kong:
    1. Go to KONG Documentation and select the Kong version you have installed.
    2. Click Configuration file and follow the instruction.
    3. 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
    4. Open /etc/kong/kong.yml in your favourite text editor.
    5. Find the hosts: property under cassandra: and change it to look like the following:
      hosts:
      - "1.1.1.1"
      - "2.2.2.2"
      
    6. For Kong 0.4.2 and later this needs to look like:
      hosts:
      - "1.1.1.1:9042"
      - "2.2.2.2:9042"
      
  7. Start Kong and test:
    1. Run:
      kong start
    2. Configure an API and run some transactions following instructions in the Kong docs quick start (https://getkong.org/docs/0.11.x/getting-started/quickstart/)
  8. Optionally Connect via cqlsh and view some of the data created:
    1. 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).
    2. From the cqlsh> prompt run:
      use kong;
      to use the kong keyspace.
    3. Run:
      select * from apis;

 

Last updated:
If you have questions regarding this article, feel free to add it to the comments below.

0 Comments

Please sign in to leave a comment.