About kong:
Kong is a high-availability, easy-to-extend API Gateway project written by Mashape based on the Nginx_Lua module. Since Kong is based on Nginx, multiple Kong servers can be scaled horizontally, and requests are evenly distributed to each server through the pre-load balancing configuration to deal with a large number of network requests. ---The official description is far-fetched, and it is not easy to understand its meaning. The popular understanding is that the third-party API gateway of the collection plug-in is similar to the integrated application. webmin.wdcp.phpstudy -- etc.
Before we play with kong, let's take a look at the api gateway.
API Gateway, that is, API Gateway, is a barrier designed to protect internal services in large-scale distributed systems. It can provide high-performance, high-availability API hosting services, thereby helping service developers to provide external services conveniently without using Considering issues such as security control, traffic control, and audit logs, implement security authentication, traffic control, audit logs, and black and white lists at the gateway layer in a unified manner. The next layer of the gateway is the internal service, and the internal service only needs to develop and focus on the implementation related to the specific business. The gateway can provide main functions such as API publishing, management, and maintenance. Developers only need a simple configuration operation to publish the services they develop and place them under the protection of the gateway.
Kong has three main components:
- Kong Server: An nginx-based server that receives API requests.
- Apache Cassandra/PostgreSQL: used to store operational data.
- Kong dashboard: The official recommended UI management tool, of course, you can also use the restfull method to manage the admin api.
Kong uses the plug-in mechanism for function customization, and the plug-in set (which can be 0 or n) is executed in the life cycle of the API request response cycle. The plugin is written in Lua and currently has several basic functions : HTTP basic authentication, key authentication, CORS (Cross-origin Resource Sharing), TCP, UDP, file logs, API request current limiting, request forwarding and nginx monitoring.
Kong official website: https://getkong.org/Plugin introduction, help documentation, etc.
Kong source code: https://github.com/Mashape/kong
Kong UI management tool: https://github.com/PGBI/kong-dashboard browser UI management tool
Kong desktop management tool: https://github.com/ajaysreedhar/kongdash has linux version, windows version, mac version.
Community Resources and Tools
How to install KONG
Can choose different ways to install -> Important
- Kong Docker: A Dockerfile for running Kong in Docker.
- Kong Packages: Pre-built packages for Debian, Red Hat, and OS X distributions (shipped with each release).
- Kong Vagrant: A Vagrantfile for provisioning a development ready environment for Kong.
- Kong Homebrew: Homebrew Formula for Kong.
- Kong CloudFormation: Kong in a 1-click deployment for AWS EC2
- Kong AWS AMI: Kong AMI on the AWS Marketplace.
- Kong on Microsoft Azure: Run Kong using Azure Resource Manager.
- Kong on Heroku: Deploy Kong on Heroku in one click.
- Kong and Instaclustr: Let Instaclustr manage your Cassandra cluster.
Third-party management and maintenance tools
- Ansible role for Kong on Ubuntu
- Biplane : declarative configuration in Crystal Crystal language version declarative configuration management tool, using configuration, one-click batch execution.
- Bonobo: key management (with Mashery migration scripts)
- Chef cookbook
- Django Kong Admin : Admin UI in Python Python version UI interface management tool
- Jungle : Admin UI in JavaScript JS version UI interface management tool
- Kong Dashboard : Admin UI in JavaScript JS version UI interface management tool
- Kong for CanopyCloud
- Kong image waiting for Cassandra
- Kong image for Tutum
- Kong-UI : Admin UI in JavaScript JS version UI interface management tool
- Konga : CLI Admin tool in JavaScript JS client management tool
- Kongfig : Declarative configuration in JavaScript JS language version declarative configuration management tool, using configuration, one-click batch execution.
- Kongfig on Puppet Forge
- Puppet recipe
- Puppet module on Puppet Forge
- Python-Kong : Admin client library for Python Python client.
- .NET-Kong : Admin client library for .NET .NET client.
- kong-java-client : Admin client library for Java java client
resource
- The story behind Kong
- Kong mentioned for the Empire PaaS
- Realtime API Management with Pushpin
- How to create your own Kong plugin
- Instaclustr partners with Kong
- How to deploy Kong on Azure
- Kong intro in Portuguese
- Kong tutorial in Japanese 1
- Kong tutorial in Japanese 2
- HAProxy + Kong
- Learn Lua in 15 minutes
- A Question about Microservices
- Kong Intro in Chinese
The above is a summary of official knowledge and personal experience. If you don't understand, you can leave a message or email to discuss.
The following is based on the company's microservice api-gateway for the use of kong research documents, the details are as follows
ong is an off-the-shelf api gateway solution developed on nginx.
There are many ways to implement api gateway. For example, NIO-based frameworks such as Netty, Vertx, Spring Reactor, and JOSS Undertow can be used on the JVM. Now a comparison process that is not based on JVM is NodeJs. Others are Nginx Plus.
The following introduces the use of Kong.
-
3.1 Install Kong
-
3.2 Add API
3.1 Install Kong
Reference: https://getkong.org/install/ , which is written in more detail, but a Cassandra database must be pre-installed (introduction: http://cassandra.apache.org/ ). After installation, the Kong project will monitor two ports, one is 8000 and the other is 8001. Port 8000 can be accessed by users, which means that users send requests to port 8000 of the Kong project first, and then the Kong project can help you go to your back-end application api. The 8001 port is the management port. For example, the administrator can get the api you have joined through the 8001 port.
3.2 Add API
Reference document: https://getkong.org/docs/0.5.x/admin-api/ , which introduces the management of api, including additions, deletions, and changes. Here are some points that were unclear when I used it for the first time:
3.2.1 List the added api
curl localhost:8001/apis/
3.2.2 Add API
Single join:
curl -i -X POST --url http://localhost:8001/apis/ --data 'upstream_url=http://camp.uats.cc' --data 'request_path=login'
The above command says:
-
--url: http://localhost:8001/apis/ is fixed, you have to write this to join the api, indicating that it is managed by kong.
-
upstream_url: Indicates our website. Equivalent to a request prefix.
-
request_path: is our specific api.
Deploy all apis using request_host:
curl -i -X POST --url http://localhost:8001/apis/ --data 'upstream_url=http://183.131.76.124:4100/' --data 'request_host=183.131.76.122'
3.2.3 delete api
curl -i -X DELETE localhost:8001/apis/00f90ca9-cf2d-4830-c842-3b90f6cd08af
The latter string represents the id of the added api.