I have a Kong API gateway deployment with several services. The default Kong timeout is set to 1 mins, which fails several of our API requests. Now I want to change them to 10 mins, without going through too much trouble. What should I do? I found this nice tool called Deck, thanks to a blogpost.
To test, let's create a service definition. $ curl -i -X POST --url http://localhost:8001/services/ --data 'name=v4' --data 'url=http://172.20.11.223:9099/services/v4'
Check the services via a browser (or a curl command, if you prefer it that way).
In this post we will briefly look into configuring Kong using its Docker container as an API gateway for your backend services. This document uses Kong version 0.14.0-alpine, which is the current latest version of Kong. Kong can be configured with Postgres or Cassandra backend for its persistent storage. Here we will configure Kong with Postgres.
Install and Start Kong with Postgres
You have 2 options. If you want to get it done quick, I recommend choosing the option #2 - installing via Docker containers.
1. Download Kong's native installation for your operating system
Optionally, you may also use these scripts to configure OpenDJ LDAP directory as a Docker container a well, connected to Docker. However, the commands are commented out - therefore you will need to uncomment the relevant commands in the script buildRun script to get it working.
Kong has two interfaces. One is the user-facing interface and the other one is the admin interface. The admin interface by default listens to the port 8001 and should not be exposed to the public. The admin interface is used by the administrators to create and configure the routes to the services in the Kong API gateway. The user-facing interface by default listens to the port 8000. It is exposed to the public, and the users can consume the services defined by the admin previously using the user-facing interface. The user-facing interface is completely separated by Kong from the admin interface.
Configure Kong for your Services
Configuring Kong as an API gateway for your services is a 2-step procedure, starting from Kong 0.14. Previous versions of Kong provided a unified approach through its "api" objects, which is current depreciated and replaced by two entities known as "services" and "routes".
Make sure that you have Kong up and running. Then, execute the below two commands from the server that hosts Kong.
First, you need to define a "service" in Kong to each of your service/API groups (i.e., your backend applications or web services).
Above, we assume your web application is hosted in http://172.20.11.223:9099/ and it has a set of services under the base path /services/v4/TCIA/query/. We pass the complete url of the backend of the original service deployments through the "url" flag, as shown above. We create a service named "radiology" in Kong for these services, using the Kong admin interface for the creation of services. Here, we assume Kong is hosted in localhost, with its admin interface using the default port option of 8001. /services/ let you create/modify the service definitions in Kong.
Second, you should add a "route" to the "radiology" service that you created.
As shown above, we use the KONG-ADMIN-INTERFACE/services/SERVICE-NAME/routes to configure the routes to the service that we defined above. Here the SERVICE-NAME is "radiology" as we defined above in the previous step. The "paths" flag indicate the paths that Kong should match to the service that we defined in the previous step.
You may of course do additional tasks such as rate limiting, request/response transformations, logging, and analytics with the Kong API Gateway. You may refer to the Kong documentation on pointers to achieving this.
Error: Failed installing dependency: http://luarocks.org/repositories/rocks/lrexlib-pcre-2.7.2-1.src.rock - Could not find expected file pcre.h for PCRE -- you may have to install PCRE in your system and/or pass PCRE_DIR or PCRE_INCDIR to the luarocks command. Example: luarocks install lrexlib-pcre PCRE_DIR=/usr/local make: *** [install] Error 1
apt-get install libpcre3 libpcre3-dev
Missing dependencies for kong: lua_uuid ~> 0.2.0-2 .. gcc -O2 -fPIC -I/usr/include/lua5.1 -c lua_uuid.c -o lua_uuid.o lua_uuid.c:9:23: fatal error: uuid/uuid.h: No such file or directory #include ^ compilation terminated.
Yagheli da?
I am Pradeeban, an Assistant Professor of Computer Science at the University of Alaska Anchorage. My research focuses on networking and big data innovations for healthcare and Circumpolar North.
Before moving to Alaska, as a Postdoctoral Researcher at the Department of Biomedical Informatics, Emory University, Atlanta, GA, USA. I researched and built efficient frameworks to schedule and execute biomedical informatics workflows.
I have an EU Erasmus Mundus Joint Doctorate in Distributed Computing (EMJD-DC) from INESC-ID Lisboa / Instituto Superior Técnico, Universidade de Lisboa, Portugal and Université catholique de Louvain, Belgium. I received my MSc degree, Erasmus Mundus European Master in Distributed Computing (EMDC), from Instituto Superior Técnico, Portugal, and KTH Royal Institute of Technology, Sweden.