DEV Community

Pierangelo
Pierangelo

Posted on

4 4

kong api gateways with docker

KONG is a api gateway placed above the microservices aimed to managing the APIs and interactions external and internal with them in a more rational, efficient, safe and "easy" way, helping the developer in the separation between public and private APIs, improving their performance , facilitating monitoring etc ...

Some Characteristic:

  • Built on NGINX
  • For the most part written in LUA
  • Expandable via many Plugins
  • It supports two types of Datastores, which can also be used simultaneously (Postgres, cassandra)

Advantages:

  • Easy management of APIs in a Microservice architecture
  • helps in the separation between Public and Private APIs
  • allows to measure and possibly limit the use of these APIs.
  • Improves performance / through the use of caching etc ...)
  • Expandable through many plugins

The best way for move the fists step with KONG is using docker:

first, create and internal network for the dockers:

docker network create kong-net
Enter fullscreen mode Exit fullscreen mode

create a container for cassandra db:

docker run -d --name kong-cassandra-database \
              --network=kong-net \
              -p 9042:9042 \
              cassandra:3
Enter fullscreen mode Exit fullscreen mode

create a postgre sql container:

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

create a migration:

docker run --rm \
    --network=kong-net \
    -e "KONG_DATABASE=postgres" \
    -e "KONG_PG_HOST=kong-postgres-database" \
    -e "KONG_CASSANDRA_CONTACT_POINTS=kong-postgres-database" \
    kong:latest kong migrations up
Enter fullscreen mode Exit fullscreen mode

create a kong container connected to the postgres and cassandra databases throught the internal network kong-net:

docker run -d --name kong \
    --network=kong-net \
    -e "KONG_DATABASE=postgres" \
    -e "KONG_PG_HOST=kong-postgres-database" \
    -e "KONG_CASSANDRA_CONTACT_POINTS=kong-cassandra-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 8001:8001 \
    -p 8444:8444 \
    kong:latest
Enter fullscreen mode Exit fullscreen mode

check on url http://localhost:8001/

For more info, go on official web site here

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay