KONG API Gateway in Docker

Slide Presentation : https://www.slideshare.net/agustox/kongapigatewaypptx

API Gateway vs Load Balance vs Reverse Proxy

What is Kong?

Kong is a scalable, open source API Platform (also known as an API Gateway or API Middleware). Kong was originally built by Kong Inc. (formerly known as Mashape) to secure, manage, and extend over 15,000 Microservices for its API Marketplace, which generates billions of requests per month.

Under active development, Kong is now used in production at hundreds of organizations from startups, to large enterprises and governments including: The New York Times, Expedia, Healthcare.gov, The Guardian, Condè Nast, The University of Auckland, Ferrari, Rakuten, Cisco, SkyScanner, Yahoo! Japan, Giphy and so on.

Kong’s official documentation can be found at docs.konghq.com.

KONG Architecture

Kong Server: This component acts as a proxy for all requests. It consists of a public layer through which all requests for accessing the APIs it exposes are funneled, and a private layer for managing and configuring those APIs. Also, it allows us to enable, disable and configure the installed plugins.

Kong Datastore: an external database where all Kong configurations are stored, along with their plugins or APIs. The datastores supported by default are Cassandra and PostgreSQL. Important: Kong uses its own cache memory to run. However, in certain cases, some plugins such as rate-limiting, require additional components such as Redis

Why Use Kong ?

Kong Ports :

  • 8000 – for proxying. This is where Kong Listens for http traffic
  • 8443 – for proxying https traffic
  • 8001 – provides Kong’s admin API that you can use to operate Kong
  • 7946 – Which Kong uses for inter-nodes communication with other Kong Nodes both UDP dan TCP traffic must be allowed
  • 7373 – used by Kong to communicate with the local clustering agent

Install KONG Community Edition in Docker

1.Install Network for KONG

docker network create kong-net

2. Install Database for Kong (Postgres Version)     

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

3. Setting Kong Database     

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

4. Then create a kong container and customize the network and db     

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_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=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:latest

5. Test Kong , URL : http://localhost:8001/

Point 1-5 are done, it is meant that Kong API gateway and database already all set-up.

Install Konga (Kong Dashboard) in Docker

  1. Install Konga
docker run -d -p 1337:1337 --network=kong-net --name konga -v /var/data/kongadata:/app/kongadata -e "NODE_ENV=production" pantsel/konga 2. Set up a network for k

2. Set up a network for konga, namely the kong-net network and set up the PostgreSQL db.

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

3. If successful run the konga and type : http://localhost:1337/

4. Create username and password , then login

5. Goto menu connection and Click button New Connection

6. Type the connection name : kong-net and URL : http://kong:8001 and then Activate

KB :

https://hub.docker.com/_/kong

https://medium.com/telkomdev/berkenalan-dengan-kong-api-gateway-dan-mencobanya-dengan-docker-a4445355493a

https://medium.com/@skzulka/cara-install-kong-konga-di-docker-desktop-windows-6fae9660819a

https://docs.konghq.com/gateway/latest/install/docker/