Kong gateway research document (go to the world translator)

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

Third-party management and maintenance tools 

resource

 

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.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325681057&siteId=291194637