Detailed tutorial on installing and using Kong API Gateway with Docker

Detailed tutorial on installing and using Kong API Gateway with Docker

1 Introduction

Kong is not a simple product. The Kong mentioned in this article mainly refers to Kong API Gateway, that is, API Gateway. This time we will just have a simple experience, install it through Docker, and then use its Route function.

2 Installation

Create a Docker Network:

# Create$ docker network create kong-net
# Check $ docker network list

Kong can be used in no-database mode. To take a peek at its configuration, we still use the database and start it as follows:

$ docker run -itd --network=kong-net \
    --name kong-database \
    -e POSTGRES_DB=kong \
    -e POSTGRES_USER=pkslow \
    -e POSTGRES_PASSWORD=pkslow-kong \
    -p 5432:5432 \
    postgres:13

Next, perform the migrations operation, which can be understood as preparing the database:

$ docker run --rm \
     --network=kong-net \
     -e "KONG_DATABASE=postgres" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_PG_USER=pkslow" \
     -e "KONG_PG_PASSWORD=pkslow-kong" \
     kong:2.5.0-ubuntu kong migrations bootstrap 

Once everything is ready, you can start Kong:

$ docker run -itd --name kong \
     --network=kong-net \
     -e "KONG_DATABASE=postgres" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_PG_USER=pkslow" \
     -e "KONG_PG_PASSWORD=pkslow-kong" \
     -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=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
     -p 8000:8000 \
     -p 8443:8443 \
     -p 127.0.0.1:8001:8001 \
     -p 127.0.0.1:8444:8444 \
     kong:2.5.0-ubuntu

Its Admin port is 8001, which can be verified by the following command:

$ curl -i http://localhost:8001/

3 Test the Route function

First create a service, which can be understood as registering a service. The service name is pkslow and the address is (www.pkslow.com):

$ curl -X POST --url http://localhost:8001/services/ --data 'name=pkslow' --data 'url=https://www.pkslow.com'

Create a routing rule with the path /pkslow and the corresponding service pkslow:

$ curl -X POST --url http://localhost:8001/services/pkslow/routes --data 'paths[]=/pkslow'

In this way, when we access the path /pkslow, other accesses are the contents of the service pkslow.

Access the test, note that the port is 8000:

$ curl -i -X ​​GET --url http://localhost:8000/pkslow

At this point, we have successfully installed and used the Route function of Kong Gateway.

4 Conclusion

The power of Kong lies in the fact that it can install many plug-ins to implement various functions, such as verification, current limiting, caching, etc. Its power is waiting for you to explore.

This is the end of this article about the detailed tutorial on how to install and use Kong API Gateway with Docker. For more information about installing Kong API Gateway with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Use docker to build kong cluster operation
  • Example of how to install kong gateway in docker

<<:  50 Super Handy Tools for Web Designers

>>:  MySQL data insertion optimization method concurrent_insert

Recommend

12 Useful Array Tricks in JavaScript

Table of contents Array deduplication 1. from() s...

How to create dynamic QML objects in JavaScript

1. Dynamically create objects There are two ways ...

Example to explain the size of MySQL statistics table

Counting the size of each table in each database ...

Use pictures to realize personalized underline of hyperlinks

Don't be surprised if you see some kind of und...

Linux installation apache server configuration process

Prepare the bags Install Check if Apache is alrea...

React+Antd implements an example of adding, deleting and modifying tables

Table of contents Table/index.js Table/model/inde...

Solve the problem of using linuxdeployqt to package Qt programs in Ubuntu

I wrote some Qt interface programs, but found it ...

Solutions to black screen when installing Ubuntu (3 types)

My computer graphics card is Nvidia graphics card...

The use of vue directive v-bind and points to note

Table of contents 1. v-bind: can bind some data t...

Solve the error during connect exception in Docker

When you first start using Docker, you will inevi...

Ubuntu 19.04 installation tutorial (picture and text steps)

1. Preparation 1.1 Download and install VMware 15...

Detailed explanation of the use of docker tag and docker push

Docker tag detailed explanation The use of the do...

Detailed explanation of how to introduce custom fonts (font-face) in CSS

Why did I use this? It all started with the makin...