Kong uses the docker environment to install

One, create a Docker network

docker network create kong-net

If you are creating a custom network, the following prompt appears:

Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network 1

It may be because Docker supports 30 different custom bridge networks by default. If this limit is exceeded, the above error will be prompted. You can use the command docker network ls to view the network you created, and then use the docker network prune command to remove the unused network.

Second, install the database

Database version can be customized

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

After the database is installed, you can enter the postgres container to create the kong user and database kong. The steps are as follows:

#Enter the postgres container

docker exec -it container_id /bin/bash
#切换用户
su postgres
#进入命令
psql;
#创建用户kong及密码
create user kong with password 'kong';
#创建数据库kong
create database kong owner kong;
#查看创建后的数据库(可省)
\l

Three, initialize the database

docker run --rm \
 --network=kong-net \
 -e "KONG_DATABASE=postgres" \
 -e "KONG_PG_HOST=kong-database" \
 -e "KONG_PG_PASSWORD=kong" \
 kong:0.13.1 kong migrations up

Fourth, install Kong mirror and start Kong

After the database is installed and initialized according to the specified Kong version, you can now drag the image through docker and start Kong

docker run -d --name kong \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_PASSWORD=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 8001:8001 \
-p 8444:8444 \
 kong:0.13.1

5. Verify Kong

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

6. Management dashboard

Migrate konga data table to pgsql

docker run --name konga --rm \
--network=kong-net \
pantsel/konga -c prepare -a postgres -u postgresql://postgres:postgres@kong-database:5432/postgres

Start konga

docker run -p 1337:1337 -d \
--network=kong-net \
-e "DB_ADAPTER=postgres" \
-e "DB_HOST=kong-database" \
-e "DB_USER=postgres" \
-e "DB_PASSWORD=postgres" \
-e "DB_DATABASE=postgres" \
-e "KONGA_HOOK_TIMEOUT=120000" \
-e "DB_PG_SCHEMA=public" \
-e "NODE_ENV=production" \
--name konga \
pantsel/konga

Visit konga: http://ip:1337, register the admin account, and add the management url of kong to konga after login: http://kong:8001
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_34758074/article/details/109228242