Kong API Gateway
Cloud-native API gateway built on NGINX with plugins ecosystem.
Overview
Kong API Gateway is a cloud-native, high-performance API gateway built on NGINX that serves as the control layer for API traffic management. Originally developed by Kong Inc. and now widely adopted in enterprise environments, Kong provides a plugin-based architecture that enables comprehensive API management including authentication, rate limiting, analytics, and request transformation. This deployment creates a complete Kong environment with three services: a PostgreSQL database (kong-database) for storing Kong's configuration and metadata, a one-time migration service (kong-migration) that initializes the database schema, and the main Kong gateway service that handles all API traffic and administrative functions. The setup provides both proxy endpoints for client traffic and admin APIs for configuration management, making it suitable for production API gateway scenarios. This configuration is ideal for organizations implementing microservices architectures, API-first development strategies, or needing centralized API management with enterprise-grade features. The PostgreSQL backend ensures Kong's configuration is persistent and allows for advanced features like clustering and high availability, while the declarative configuration approach enables infrastructure-as-code practices for API management.
Key Features
- Plugin-based architecture with 50+ official plugins for authentication, security, traffic control, and analytics
- Declarative configuration supporting both database and DB-less modes for GitOps workflows
- Advanced rate limiting with Redis clustering support and multiple algorithms (sliding window, fixed window)
- Multi-protocol support including HTTP/HTTPS, gRPC, GraphQL, and WebSocket proxying
- Service mesh integration with native Kubernetes ingress controller capabilities
- Real-time analytics and monitoring with Prometheus metrics and custom logging plugins
- JWT, OAuth 2.0, LDAP, and custom authentication mechanisms with fine-grained access control
- Request/response transformation including header manipulation, body transformation, and CORS handling
Common Use Cases
- 1Enterprise API management for microservices architectures with centralized authentication and rate limiting
- 2Multi-tenant SaaS platforms requiring per-customer API quotas and usage analytics
- 3Legacy system modernization with API versioning and gradual migration strategies
- 4Developer portal backends with API key management and usage tracking
- 5Kubernetes-native API gateway with service discovery and load balancing
- 6API security enforcement with WAF capabilities and threat detection
- 7GraphQL federation gateway combining multiple GraphQL services into unified APIs
Prerequisites
- Minimum 1GB RAM for Kong service and 512MB for PostgreSQL database
- Ports 8000 (HTTP proxy), 8001 (Admin API), 8443 (HTTPS proxy), 8444 (HTTPS Admin) available
- Environment variable KONG_PG_PASSWORD configured for database authentication
- Understanding of RESTful API concepts and HTTP routing for service configuration
- Familiarity with PostgreSQL for database maintenance and backup procedures
- Knowledge of plugin ecosystem and YAML/JSON for declarative configurations
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 container_name: kong-database5 restart: unless-stopped6 environment: 7 POSTGRES_USER: kong8 POSTGRES_PASSWORD: ${KONG_PG_PASSWORD}9 POSTGRES_DB: kong10 volumes: 11 - kong_data:/var/lib/postgresql/data12 networks: 13 - kong-network1415 kong-migration: 16 image: kong:latest17 command: kong migrations bootstrap18 environment: 19 KONG_DATABASE: postgres20 KONG_PG_HOST: kong-database21 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}22 depends_on: 23 - kong-database24 networks: 25 - kong-network2627 kong: 28 image: kong:latest29 container_name: kong30 restart: unless-stopped31 environment: 32 KONG_DATABASE: postgres33 KONG_PG_HOST: kong-database34 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}35 KONG_PROXY_ACCESS_LOG: /dev/stdout36 KONG_ADMIN_ACCESS_LOG: /dev/stdout37 KONG_PROXY_ERROR_LOG: /dev/stderr38 KONG_ADMIN_ERROR_LOG: /dev/stderr39 KONG_ADMIN_LISTEN: 0.0.0.0:800140 ports: 41 - "8000:8000"42 - "8443:8443"43 - "8001:8001"44 - "8444:8444"45 depends_on: 46 - kong-database47 - kong-migration48 networks: 49 - kong-network5051volumes: 52 kong_data: 5354networks: 55 kong-network: 56 driver: bridge.env Template
.env
1KONG_PG_PASSWORD=changemeUsage Notes
- 1Docs: https://docs.konghq.com/gateway/latest/
- 2Admin API at http://localhost:8001 - manage routes, services, plugins
- 3Proxy ports: 8000 (HTTP), 8443 (HTTPS) - client traffic here
- 4Add service: curl -X POST http://localhost:8001/services --data name=myapp --data url=http://backend:80
- 5Add route: curl -X POST http://localhost:8001/services/myapp/routes --data paths[]=/api
- 6Install Konga or Kong Manager for web UI management
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
kong-database
kong-database:
image: postgres:15-alpine
container_name: kong-database
restart: unless-stopped
environment:
POSTGRES_USER: kong
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD}
POSTGRES_DB: kong
volumes:
- kong_data:/var/lib/postgresql/data
networks:
- kong-network
kong-migration
kong-migration:
image: kong:latest
command: kong migrations bootstrap
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}
depends_on:
- kong-database
networks:
- kong-network
kong
kong:
image: kong:latest
container_name: kong
restart: unless-stopped
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
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
ports:
- "8000:8000"
- "8443:8443"
- "8001:8001"
- "8444:8444"
depends_on:
- kong-database
- kong-migration
networks:
- kong-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 kong-database:5 image: postgres:15-alpine6 container_name: kong-database7 restart: unless-stopped8 environment:9 POSTGRES_USER: kong10 POSTGRES_PASSWORD: ${KONG_PG_PASSWORD}11 POSTGRES_DB: kong12 volumes:13 - kong_data:/var/lib/postgresql/data14 networks:15 - kong-network1617 kong-migration:18 image: kong:latest19 command: kong migrations bootstrap20 environment:21 KONG_DATABASE: postgres22 KONG_PG_HOST: kong-database23 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}24 depends_on:25 - kong-database26 networks:27 - kong-network2829 kong:30 image: kong:latest31 container_name: kong32 restart: unless-stopped33 environment:34 KONG_DATABASE: postgres35 KONG_PG_HOST: kong-database36 KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}37 KONG_PROXY_ACCESS_LOG: /dev/stdout38 KONG_ADMIN_ACCESS_LOG: /dev/stdout39 KONG_PROXY_ERROR_LOG: /dev/stderr40 KONG_ADMIN_ERROR_LOG: /dev/stderr41 KONG_ADMIN_LISTEN: 0.0.0.0:800142 ports:43 - "8000:8000"44 - "8443:8443"45 - "8001:8001"46 - "8444:8444"47 depends_on:48 - kong-database49 - kong-migration50 networks:51 - kong-network5253volumes:54 kong_data:5556networks:57 kong-network:58 driver: bridge59EOF6061# 2. Create the .env file62cat > .env << 'EOF'63KONG_PG_PASSWORD=changeme64EOF6566# 3. Start the services67docker compose up -d6869# 4. View logs70docker 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-gateway/run | bashTroubleshooting
- kong-migration service fails with connection refused: Ensure kong-database container is fully started and accepting connections before migration runs
- Admin API returns 404 on localhost:8001: Verify KONG_ADMIN_LISTEN environment variable is set to 0.0.0.0:8001 and port mapping is correct
- Kong service shows 'database not ready' errors: Check PostgreSQL logs in kong-database container and ensure KONG_PG_PASSWORD matches POSTGRES_PASSWORD
- Proxy returns 404 for configured routes: Verify services and routes are properly created via Admin API and check Kong's error logs for routing issues
- High memory usage in kong container: Monitor plugin usage and consider disabling unused plugins or increasing memory limits for heavy traffic loads
- PostgreSQL connection pool exhausted: Tune KONG_PG_MAX_CONCURRENT_QUERIES and PostgreSQL max_connections settings for high-throughput scenarios
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
kongpostgresql
Tags
#kong#api-gateway#nginx#microservices#plugins
Category
Web Servers & Reverse ProxiesAd Space
Shortcuts: C CopyF FavoriteD Download