Skip to content

GloballogicPractices/kong-custom-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kong-custom-plugin

Trying to help people who really want to work with KONG API gateway custom plugin.

image

What is KONG?

Kong is a scalable, open source API Gateway. Kong runs in front of any RESTful API and is extended through Plugins, which provide extra functionality and services beyond the core platform.

  • Scalable: Kong easily scales horizontally by simply adding more machines, meaning your platform can handle virtually any load while keeping latency low.

  • Modular: Kong can be extended by adding new plugins, which are easily configured through a RESTful Admin API.

  • Runs on any infrastructure: Kong runs anywhere. You can deploy Kong in the cloud or on-premise environments, including single or multi-datacenter setups and for public, private or invite-only APIs.

Kong is built on top of reliable technologies like NGINX and Apache Cassandra or PostgreSQL, and provides you with an easy-to-use RESTful API to operate and configure the system.

image

What is KONG Plugin?

kong has plugins oriented architecture. All of these Kong plugins give you the power to transform the requests and responses, to control the access of APIs, to log and measure the APIs calls, etc.

image

In some cases when existing plugin does not solve your problem than you have to write custom plugin. Check available plugins detail at https://konghq.com/plugins/

  • Installation

    • Go inside the KONG container

      • docker exec -it kong-container-id bash
    • Download code

    • Set Environment Variables

      • export KONG_CUSTOM_PLUGINS="kong-custom-plugin"
      • export KONG_LUA_PACKAGE_PATH="/kong-custom-plugin/lua_modules/share/lua/5.1/kong/plugins/kong-custom-plugin/?.lua"
    • Build & Deploy plugin

      • cd kong-custom-plugin
      • luarocks make
      • make install-dev
      • kong reload -vv
    • View Plugin

    image

  • Remove a plugin There are three steps to completely remove a plugin.

    • Remove the plugin from your Kong api configuration. Make sure that it is no longer applied globally nor for any API or consumer. This has to be done only once for the entire Kong cluster, no restart/reload required. This step in itself will make that the plugin is no longer in use. But it remains available and it is still possible to re-apply the plugin.

    • Remove the plugin from the custom_plugins directive (on each Kong node). Make sure to have completed step 1 before doing so. After this step it will be impossible for anyone to re-apply the plugin to any Kong api, consumer, or even globally. This step requires to restart/reload the Kong node to take effect.

    • To remove the plugin thoroughly, delete the plugin-related files from each of the Kong nodes. Make sure to have completed step 2, including restarting/reloading Kong, before deleting the files. If you used LuaRocks to install the plugin, you can do luarocks remove to remove it

  • Next

    • You can write your custom bussiness logic at handler.lua file.
    • You can refer existing official kong plugin code for more detail.

About

Kong API Gateway Custom plugin Hello World Sample

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages