Kong API Gateway Enterprise Stack
Full Kong Gateway with plugins, Konga admin UI, and PostgreSQL backend.
Overview
Kong is a cloud-native API gateway built on OpenResty and designed to handle millions of API requests for modern architectures. Originally developed by Mashape (now Kong Inc.) in 2015, Kong has become one of the most widely adopted API gateways, offering traffic control, security, analytics, and transformation capabilities through its extensive plugin ecosystem. It serves as a central control point for API traffic, providing rate limiting, authentication, load balancing, and request/response transformation.
This enterprise-grade deployment creates a comprehensive API management platform with six specialized services: a PostgreSQL database (kong-database) for Kong's configuration storage, an initialization service (kong-migrations) to bootstrap the database schema, the main Kong gateway instance, Konga as a web-based administration interface, Prometheus for metrics collection, and Grafana for visualization and monitoring dashboards. The stack uses PostgreSQL as Kong's backing store instead of the simpler DB-less mode, enabling advanced features like clustering and plugin data persistence.
This configuration is ideal for organizations transitioning from monolithic architectures to microservices, platform teams building internal API platforms, and enterprises requiring sophisticated API governance with full observability. The combination of Kong's enterprise-class gateway capabilities with Konga's intuitive management interface and the Prometheus-Grafana monitoring stack provides everything needed to operate APIs at scale with proper visibility into performance and usage patterns.
Key Features
- Plugin-based architecture with 50+ community and enterprise plugins for authentication, rate limiting, and transformations
- Konga web interface for visual API gateway management, service configuration, and plugin administration
- PostgreSQL-backed configuration enabling Kong clustering, plugin data persistence, and advanced routing rules
- Prometheus metrics collection with Kong-specific performance indicators and API usage statistics
- Grafana dashboards for real-time API gateway monitoring, traffic analysis, and SLA tracking
- Declarative configuration support for GitOps workflows and infrastructure-as-code deployments
- Multi-protocol support including HTTP/HTTPS, gRPC, WebSocket, and TCP stream proxying
- Database migration automation ensuring proper Kong schema initialization and upgrades
Common Use Cases
- 1Microservices API gateway providing unified entry point for distributed service architectures
- 2Enterprise API management platform with centralized authentication, rate limiting, and analytics
- 3Developer portal backend offering API discovery, documentation, and self-service onboarding
- 4Multi-tenant SaaS platforms requiring per-customer rate limiting, authentication, and usage tracking
- 5Legacy system modernization providing modern API interfaces over existing backend services
- 6Internal API platform for large organizations standardizing service-to-service communication
- 7E-commerce platforms managing high-volume API traffic with sophisticated caching and transformation needs
Prerequisites
- Docker Engine 20.10+ and Docker Compose v2 with at least 4GB RAM available for the complete stack
- Available ports 8000, 8001, 8002, 8443, 8444 for Kong services, plus 1337 for Konga, 9090 for Prometheus, and 3000 for Grafana
- Understanding of API gateway concepts, HTTP routing, and basic Kong plugin configuration
- Prometheus configuration file (prometheus.yml) in the project directory for metrics collection setup
- Environment variables KONG_PG_PASSWORD and GRAFANA_PASSWORD configured for database and admin access
- Basic knowledge of PostgreSQL administration for backup, maintenance, and performance tuning
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 kong-database: 3 image: postgres:15-alpine4 environment: 5 POSTGRES_USER: kong6 POSTGRES_DB: kong7 POSTGRES_PASSWORD: ${KONG_PG_PASSWORD}8 volumes: 9 - kong_db:/var/lib/postgresql/data10 healthcheck: 11 test: ["CMD", "pg_isready", "-U", "kong"]12 interval: 10s13 timeout: 5s14 retries: 515 networks: 16 - kong_net1718 kong-migrations: 19 image: kong:latest20 command: kong migrations bootstrap21 depends_on: 22 kong-database: 23 condition: service_healthy24 environment: 25 KONG_DATABASE: postgres26 KONG_PG_HOST: kong-database27 KONG_PG_USER: kong28 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}29 networks: 30 - kong_net31 restart: on-failure3233 kong: 34 image: kong:latest35 depends_on: 36 kong-database: 37 condition: service_healthy38 kong-migrations: 39 condition: service_completed_successfully40 environment: 41 KONG_DATABASE: postgres42 KONG_PG_HOST: kong-database43 KONG_PG_USER: kong44 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}45 KONG_PROXY_ACCESS_LOG: /dev/stdout46 KONG_ADMIN_ACCESS_LOG: /dev/stdout47 KONG_PROXY_ERROR_LOG: /dev/stderr48 KONG_ADMIN_ERROR_LOG: /dev/stderr49 KONG_ADMIN_LISTEN: 0.0.0.0:800150 KONG_ADMIN_GUI_URL: http://localhost:800251 ports: 52 - "8000:8000"53 - "8443:8443"54 - "8001:8001"55 - "8002:8002"56 - "8444:8444"57 healthcheck: 58 test: ["CMD", "kong", "health"]59 interval: 10s60 timeout: 10s61 retries: 1062 networks: 63 - kong_net6465 konga: 66 image: pantsel/konga:latest67 depends_on: 68 kong: 69 condition: service_healthy70 environment: 71 DB_ADAPTER: postgres72 DB_HOST: kong-database73 DB_USER: kong74 DB_PASSWORD: ${KONG_PG_PASSWORD}75 DB_DATABASE: konga76 NODE_ENV: production77 ports: 78 - "1337:1337"79 networks: 80 - kong_net8182 prometheus: 83 image: prom/prometheus:latest84 ports: 85 - "9090:9090"86 volumes: 87 - ./prometheus.yml:/etc/prometheus/prometheus.yml88 - prometheus_data:/prometheus89 networks: 90 - kong_net9192 grafana: 93 image: grafana/grafana:latest94 ports: 95 - "3000:3000"96 environment: 97 - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}98 volumes: 99 - grafana_data:/var/lib/grafana100 networks: 101 - kong_net102103volumes: 104 kong_db: 105 prometheus_data: 106 grafana_data: 107108networks: 109 kong_net: .env Template
.env
1# Kong Gateway2KONG_PG_PASSWORD=secure_kong_password3GRAFANA_PASSWORD=secure_grafana_password45# Proxy at http://localhost:80006# Admin API at http://localhost:80017# Konga at http://localhost:1337Usage Notes
- 1Proxy at http://localhost:8000
- 2Admin API at http://localhost:8001
- 3Konga UI at http://localhost:1337
- 4SSL proxy at https://localhost:8443
- 5Configure routes and plugins via Admin API
Individual Services(6 services)
Copy individual services to mix and match with your existing compose files.
kong-database
kong-database:
image: postgres:15-alpine
environment:
POSTGRES_USER: kong
POSTGRES_DB: kong
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD}
volumes:
- kong_db:/var/lib/postgresql/data
healthcheck:
test:
- CMD
- pg_isready
- "-U"
- kong
interval: 10s
timeout: 5s
retries: 5
networks:
- kong_net
kong-migrations
kong-migrations:
image: kong:latest
command: kong migrations bootstrap
depends_on:
kong-database:
condition: service_healthy
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
KONG_PG_USER: kong
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}
networks:
- kong_net
restart: on-failure
kong
kong:
image: kong:latest
depends_on:
kong-database:
condition: service_healthy
kong-migrations:
condition: service_completed_successfully
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
KONG_PG_USER: kong
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: 0.0.0.0:8001
KONG_ADMIN_GUI_URL: http://localhost:8002
ports:
- "8000:8000"
- "8443:8443"
- "8001:8001"
- "8002:8002"
- "8444:8444"
healthcheck:
test:
- CMD
- kong
- health
interval: 10s
timeout: 10s
retries: 10
networks:
- kong_net
konga
konga:
image: pantsel/konga:latest
depends_on:
kong:
condition: service_healthy
environment:
DB_ADAPTER: postgres
DB_HOST: kong-database
DB_USER: kong
DB_PASSWORD: ${KONG_PG_PASSWORD}
DB_DATABASE: konga
NODE_ENV: production
ports:
- "1337:1337"
networks:
- kong_net
prometheus
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
networks:
- kong_net
grafana
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}
volumes:
- grafana_data:/var/lib/grafana
networks:
- kong_net
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 kong-database:5 image: postgres:15-alpine6 environment:7 POSTGRES_USER: kong8 POSTGRES_DB: kong9 POSTGRES_PASSWORD: ${KONG_PG_PASSWORD}10 volumes:11 - kong_db:/var/lib/postgresql/data12 healthcheck:13 test: ["CMD", "pg_isready", "-U", "kong"]14 interval: 10s15 timeout: 5s16 retries: 517 networks:18 - kong_net1920 kong-migrations:21 image: kong:latest22 command: kong migrations bootstrap23 depends_on:24 kong-database:25 condition: service_healthy26 environment:27 KONG_DATABASE: postgres28 KONG_PG_HOST: kong-database29 KONG_PG_USER: kong30 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}31 networks:32 - kong_net33 restart: on-failure3435 kong:36 image: kong:latest37 depends_on:38 kong-database:39 condition: service_healthy40 kong-migrations:41 condition: service_completed_successfully42 environment:43 KONG_DATABASE: postgres44 KONG_PG_HOST: kong-database45 KONG_PG_USER: kong46 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}47 KONG_PROXY_ACCESS_LOG: /dev/stdout48 KONG_ADMIN_ACCESS_LOG: /dev/stdout49 KONG_PROXY_ERROR_LOG: /dev/stderr50 KONG_ADMIN_ERROR_LOG: /dev/stderr51 KONG_ADMIN_LISTEN: 0.0.0.0:800152 KONG_ADMIN_GUI_URL: http://localhost:800253 ports:54 - "8000:8000"55 - "8443:8443"56 - "8001:8001"57 - "8002:8002"58 - "8444:8444"59 healthcheck:60 test: ["CMD", "kong", "health"]61 interval: 10s62 timeout: 10s63 retries: 1064 networks:65 - kong_net6667 konga:68 image: pantsel/konga:latest69 depends_on:70 kong:71 condition: service_healthy72 environment:73 DB_ADAPTER: postgres74 DB_HOST: kong-database75 DB_USER: kong76 DB_PASSWORD: ${KONG_PG_PASSWORD}77 DB_DATABASE: konga78 NODE_ENV: production79 ports:80 - "1337:1337"81 networks:82 - kong_net8384 prometheus:85 image: prom/prometheus:latest86 ports:87 - "9090:9090"88 volumes:89 - ./prometheus.yml:/etc/prometheus/prometheus.yml90 - prometheus_data:/prometheus91 networks:92 - kong_net9394 grafana:95 image: grafana/grafana:latest96 ports:97 - "3000:3000"98 environment:99 - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}100 volumes:101 - grafana_data:/var/lib/grafana102 networks:103 - kong_net104105volumes:106 kong_db:107 prometheus_data:108 grafana_data:109110networks:111 kong_net:112EOF113114# 2. Create the .env file115cat > .env << 'EOF'116# Kong Gateway117KONG_PG_PASSWORD=secure_kong_password118GRAFANA_PASSWORD=secure_grafana_password119120# Proxy at http://localhost:8000121# Admin API at http://localhost:8001122# Konga at http://localhost:1337123EOF124125# 3. Start the services126docker compose up -d127128# 4. View logs129docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/kong-enterprise-gateway/run | bashTroubleshooting
- Kong container fails with 'database not ready': Ensure kong-database health check passes before Kong starts, check PostgreSQL logs for connection issues
- Konga shows 'Connection to Kong failed': Verify Kong admin API is accessible on port 8001 and kong service is healthy
- kong-migrations service exits with schema errors: Clean kong_db volume and restart to reinitialize database with proper Kong schema
- Prometheus shows no Kong metrics: Configure Kong Prometheus plugin and ensure metrics endpoint is enabled in Kong configuration
- 502 Bad Gateway on proxy port 8000: Check that upstream services are configured correctly in Kong and target backends are reachable
- Grafana dashboards show no data: Verify Prometheus data source configuration and ensure Kong metrics are being scraped successfully
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
kongpostgresqlkongaprometheusgrafana
Tags
#kong#api-gateway#microservices#plugins#konga
Category
DevOps & CI/CDAd Space
Shortcuts: C CopyF FavoriteD Download