1、下载镜像
2、安装
2.1、创建网络
2.2、安装postgres,kong依赖于postgres
2.3、初始化kong数据表信息
2.4、启动kong
2.5、初始化konga数据信息
2.6、启动konga
2.7、创建连接节点
2.8、创建Upstreams
2.9、配置services和routes
3.0、验证
3.1、其它
docker pull postgres:9.6-bullseye
docker pull kong/kong-gateway:2.4.1.0-alpine
docker pull pantsel/konga:0.14.9
docker network create yanshao_net
docker run -d --network=yanshao_net --name postgres \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kong" \
postgres:9.6-bullseye
备注:
docker run --rm --network=yanshao_net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=postgres" \
-e "KONG_PG_PASSWORD=kong" \
-e "KONG_PASSWORD=kong" \
kong/kong-gateway:2.4.1.0-alpine kong migrations bootstrap
Bootstrapping database...
migrating core on database 'kong'...
core migrated up to: 000_base (executed)
core migrated up to: 003_100_to_110 (executed)
core migrated up to: 004_110_to_120 (executed)
core migrated up to: 005_120_to_130 (executed)
core migrated up to: 006_130_to_140 (executed)
core migrated up to: 007_140_to_150 (executed)
core migrated up to: 008_150_to_200 (executed)
core migrated up to: 009_200_to_210 (executed)
core migrated up to: 010_210_to_211 (executed)
core migrated up to: 011_212_to_213 (executed)
core migrated up to: 012_213_to_220 (executed)
core migrated up to: 013_220_to_230 (executed)
migrating acl on database 'kong'...
acl migrated up to: 000_base_acl (executed)
acl migrated up to: 002_130_to_140 (executed)
acl migrated up to: 003_200_to_210 (executed)
acl migrated up to: 004_212_to_213 (executed)
migrating acme on database 'kong'...
acme migrated up to: 000_base_acme (executed)
migrating basic-auth on database 'kong'...
basic-auth migrated up to: 000_base_basic_auth (executed)
basic-auth migrated up to: 002_130_to_140 (executed)
basic-auth migrated up to: 003_200_to_210 (executed)
migrating bot-detection on database 'kong'...
bot-detection migrated up to: 001_200_to_210 (executed)
migrating canary on database 'kong'...
canary migrated up to: 001_200_to_210 (executed)
migrating degraphql on database 'kong'...
degraphql migrated up to: 000_base (executed)
migrating graphql-rate-limiting-advanced on database 'kong'...
graphql-rate-limiting-advanced migrated up to: 000_base_gql_rate_limiting (executed)
migrating hmac-auth on database 'kong'...
hmac-auth migrated up to: 000_base_hmac_auth (executed)
hmac-auth migrated up to: 002_130_to_140 (executed)
hmac-auth migrated up to: 003_200_to_210 (executed)
migrating ip-restriction on database 'kong'...
ip-restriction migrated up to: 001_200_to_210 (executed)
migrating jwt on database 'kong'...
jwt migrated up to: 000_base_jwt (executed)
jwt migrated up to: 002_130_to_140 (executed)
jwt migrated up to: 003_200_to_210 (executed)
migrating jwt-signer on database 'kong'...
jwt-signer migrated up to: 000_base_jwt_signer (executed)
jwt-signer migrated up to: 001_200_to_210 (executed)
migrating key-auth on database 'kong'...
key-auth migrated up to: 000_base_key_auth (executed)
key-auth migrated up to: 002_130_to_140 (executed)
key-auth migrated up to: 003_200_to_210 (executed)
migrating key-auth-enc on database 'kong'...
key-auth-enc migrated up to: 000_base_key_auth_enc (executed)
key-auth-enc migrated up to: 001_200_to_210 (executed)
migrating mtls-auth on database 'kong'...
mtls-auth migrated up to: 000_base_mtls_auth (executed)
mtls-auth migrated up to: 001_200_to_210 (executed)
mtls-auth migrated up to: 002_2200_to_2300 (executed)
migrating oauth2 on database 'kong'...
oauth2 migrated up to: 000_base_oauth2 (executed)
oauth2 migrated up to: 003_130_to_140 (executed)
oauth2 migrated up to: 004_200_to_210 (executed)
oauth2 migrated up to: 005_210_to_211 (executed)
migrating openid-connect on database 'kong'...
openid-connect migrated up to: 000_base_openid_connect (executed)
openid-connect migrated up to: 001_14_to_15 (executed)
openid-connect migrated up to: 002_200_to_210 (executed)
migrating proxy-cache-advanced on database 'kong'...
proxy-cache-advanced migrated up to: 001_035_to_050 (executed)
migrating rate-limiting on database 'kong'...
rate-limiting migrated up to: 000_base_rate_limiting (executed)
rate-limiting migrated up to: 003_10_to_112 (executed)
rate-limiting migrated up to: 004_200_to_210 (executed)
migrating response-ratelimiting on database 'kong'...
response-ratelimiting migrated up to: 000_base_response_rate_limiting (executed)
migrating session on database 'kong'...
session migrated up to: 000_base_session (executed)
session migrated up to: 001_add_ttl_index (executed)
migrating vault-auth on database 'kong'...
vault-auth migrated up to: 000_base_vault_auth (executed)
migrating enterprise on database 'kong'...
enterprise migrated up to: 000_base (executed)
enterprise migrated up to: 006_1301_to_1500 (executed)
enterprise migrated up to: 006_1301_to_1302 (executed)
enterprise migrated up to: 010_1500_to_2100 (executed)
enterprise migrated up to: 007_1500_to_1504 (executed)
enterprise migrated up to: 008_1504_to_1505 (executed)
enterprise migrated up to: 007_1500_to_2100 (executed)
enterprise migrated up to: 009_1506_to_1507 (executed)
enterprise migrated up to: 009_2100_to_2200 (executed)
enterprise migrated up to: 010_2200_to_2211 (executed)
enterprise migrated up to: 010_2200_to_2300 (executed)
enterprise migrated up to: 010_2200_to_2300_1 (executed)
migrating enterprise.acl on database 'kong'...
enterprise.acl migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.basic-auth on database 'kong'...
enterprise.basic-auth migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.hmac-auth on database 'kong'...
enterprise.hmac-auth migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.jwt on database 'kong'...
enterprise.jwt migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.key-auth on database 'kong'...
enterprise.key-auth migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.key-auth-enc on database 'kong'...
enterprise.key-auth-enc migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.mtls-auth on database 'kong'...
enterprise.mtls-auth migrated up to: 001_1500_to_2100 (executed)
enterprise.mtls-auth migrated up to: 002_2200_to_2300 (executed)
migrating enterprise.oauth2 on database 'kong'...
enterprise.oauth2 migrated up to: 001_1500_to_2100 (executed)
enterprise.oauth2 migrated up to: 002_2200_to_2211 (executed)
migrating enterprise.request-transformer-advanced on database 'kong'...
enterprise.request-transformer-advanced migrated up to: 001_1500_to_2100 (executed)
migrating enterprise.response-transformer-advanced on database 'kong'...
enterprise.response-transformer-advanced migrated up to: 001_1500_to_2100 (executed)
80 migrations processed
80 executed
docker run -d --name kong-ee --network=yanshao_net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=postgres" \
-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" \
-e "KONG_ADMIN_GUI_URL=http://127.0.0.1:9002" \
-p 9000:8000 \
-p 9443:8443 \
-p 9001:8001 \
-p 9444:8444 \
-p 9002:8002 \
kong/kong-gateway:2.4.1.0-alpine
kong有5个端口需要对外暴露
docker run --rm --network=yanshao_net pantsel/konga:latest -c prepare -a postgres -u postgresql://kong:kong@postgres:5432/kong
debug: Preparing database...
Using postgres DB Adapter.
Database exists. Continue...
debug: Hook:api_health_checks:process() called
debug: Hook:health_checks:process() called
debug: Hook:start-scheduled-snapshots:process() called
debug: Hook:upstream_health_checks:process() called
debug: Hook:user_events_hook:process() called
debug: Seeding User...
debug: User seed planted
debug: Seeding Kongnode...
debug: Kongnode seed planted
debug: Seeding Emailtransport...
debug: Emailtransport seed planted
debug: Database migrations completed!
docker run -d -p 1337:1337 --network yanshao_net --name konga \
-e "DB_ADAPTER=postgres" \
-e "DB_URI=postgresql://kong:kong@postgres:5432/kong" \
-e "DB_PASSWORD=kong" \
-e "NODE_ENV=production" \
pantsel/konga:0.14.9
@RestController
@RequestMapping("/user")
public class UserController {
@PostMapping("/v1/userInfo")
public Map userInfo1(){
Map res = new HashMap<>();
res.put("version","v1");
res.put("userName","Tiger");
res.put("address","beijing");
return res;
}
}
到这里,说明kong可以配置代理并且使用了!