Kong is one of the open source API gateway managers around. A typical use case is when you want to manage(eg. Secure) your API and but you don't have the time to write all those logic inside your API. API Gateway is probably what you need.
API Gateways can do- Rate limiting, securing Your API with Key and tokens, logging and many more.
We would use kong to protect Simple API I wrote with Flask. Watch out for Part 2.
There are several options for installing kong, they include Debian, docker which is very prevalent, kubernates, redhat and even vagrant.
Head over to Kong homepage download kong Debian image from kong website.
Select the one applicable and download.
- Install Kong
$ sudo apt-get install openssl libpcre3 procps perl #some dependencies
$ sudo dpkg -i kongdeb.deb
Not yet, Kong is only installed. Lets provision persistent database for it.
On your appliance assuming you installed kong on Ubuntu as I did, the default configuration would be available at
- Make a copy
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
- Configure the Datastore
Kong support Cassandra and PostgreSQL Database. I am using PostgreSQL over here.
- Provision the database
CREATE USER kong; CREATE DATABASE kong OWNER kong
- Update the
Scroll to the database section and add the Postgres details.
$ vim /etc/kong/kong.conf and change this section
dbname: kong, user=kong, pass=kong2018
kong has some commands
$ kong migrations up #runs the database migrations
$ sudo kong start
$ curl -i http://localhost:8001
$ sudo kong stop #stop kong
$ sudo kong health #kong status
NB. Watch out for Part 2, where I add the Flask API.
Level up every day