Introduction to Kong and Konga


Introduction to Kong and Konga

the front

Recently, I have been learning and understandingkongLet’s share with you todaykongandkongabar


kongIt’s based on nginx_ The gateway API written by Lua module is a gateway for forwarding API communication between client and service, which can be extended by plug-ins.

In a word:Kong is a dynamic enhanced version of nginx

Look at some nouns

  • NginxIs a modular design of reverse agent software, C language development
  • OpenRestySoNginxAs the core of web development platform, it can parse and execute Lua script
  • kongIt’s aopenRestyApplication, an API gateway

Kong installation

Mainly bydockerTo deploy. currentkongedition2.3.0

1 . Creating docker virtual network

docker network create kong-net

2 . Database running PostgreSQL

docker run -d --name kong-database \
               --network=kong-net \
               -p 5432:5432 \
               -e "POSTGRES_USER=kong" \
               -e "POSTGRES_DB=kong" \
               -e "POSTGRES_PASSWORD=kong" \

3 . Initialize database (migrate data)

docker run --rm \
     --network=kong-net \
     -e "KONG_DATABASE=postgres" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_PG_USER=kong" \
     -e "KONG_PG_PASSWORD=kong" \
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
     kong:latest kong migrations bootstrap

4 . Running Kong

docker run -d --name kong \
     --network=kong-net \
     -e "KONG_DATABASE=postgres" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_PG_USER=kong" \
     -e "KONG_PG_PASSWORD=kong" \
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
     -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
     -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
     -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
     -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
     -e "KONG_ADMIN_LISTEN=, ssl" \
     -p 8000:8000 \
     -p 8443:8443 \
     -p \
     -p \

5 . Verify that the installation is successful

// Running on the host
curl -i http://localhost:8001/

Return to the following

HTTP/1.1 200 OK
Date: Mon, 05 Apr 2021 08:37:24 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Content-Length: 10452
X-Kong-Admin-Latency: 20215
Server: kong/2.3.0


It means that the installation is correct and Kong can be used normally

Application of Kong

Kong can be generated dynamicallynginxNext, let’s demonstrate it

A typical nginx configuration file

upstream demoupstream {
        server localhost:3000 weight=100;
server {
        listen 8000;
        location /demo {
                proxy_pass http://demoupstream;

The above is simpleNginxThe configuration can be changed as followsKong configuration

1 . Configure upstream

curl -X POST http://localhost:8001/upstreams --data "name=demoupstream"

2 . Configure target

curl -X POST http://localhost:8001/upstreams/demoupstream/targets --data "target=localhost:3000" --data "weight=100"

3 . Configure service

curl -X POST http://localhost:8001/services --data "name=demo" --data "host=demoupstream" --data "url="

4 . Configure route

curl -X POST http://localhost:8001/services/demo/routes --data "paths[]=/demo" --data "hosts[]"

Of course, you can change the 8000 port to the familiar 80 port. Just change the mapping port when you start Kong.

5 . verification

curl -i http://localhost:8000/demo --header

⚠️ be careful:The target port above should be accessible locally. Remember to configure the domain name hosts

Introduction to Concept Terms

  • upstream: is an abstraction of the upstream server
  • target: represents a physical service and is an abstraction of IP + port
  • service: is an abstract level service, which can be directly mapped to a physical service (host points to IP) + port) , You can also point to oneupstreamTo achieve load balancing
  • route: is the abstraction of routing, which is responsible for the actualrequestMap toservice

Default listening port of Kong

  • 8000: listen for data from the clientHTTPTraffic, forward to yourupstreamService
  • 8443: MonitorHTTPSThe flow and function of8000Similarly, it can be disabled through the configuration file.
  • 8001kongOfHTTPAdmin API management interface for monitoring
  • 8444kongOfHTTPSAdmin API management interface for monitoring


It’s all command-line. Is there any intuitive graphical interface?

Yes, Konga is more popular. The official fee is charged. We can use the community contributor’s fee

Konga address

We use docker to install

1 . Konga also needs to create a database. Here we create and migrate the data together

docker run --rm pantsel/konga:latest -c prepare -a postgres -u postgresql://kong:[email protected]:5432/konga

Explain the parameters belowkong:[email protected]:5432/konga User name: password @ database IP: port / database name

2 . Start Konga

docker run -p 1337:1337 \
        --network kong-net \
        --name konga \
        -e "NODE_ENV=production"  \
        -e "DB_ADAPTER=postgres" \
        -e "DB_URI=postgresql://kong:[email protected]:5432/konga" \

The parameters here are relatively simple. Please see the official link above for details

3 . verification

Browser access http://localhost :1337/

Register to enter, you can see the following interface

Introduction to Kong and Konga

The name in the figure is optional. Kong admin URL is to access Kong’s admin APIhttp://kong:8001

After activation, you can see the upstream, service and route you created earlier.

Let’s play and hope to see more. You can visit Kong’s official website and learn from it


Thank you for reading this article. If there is anything wrong, please point out. Thank you

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]