Setting up Kong Gateway with high availability (HA) on-premise on bare metal servers involves several steps. Below is a comprehensive guide to achieve this setup:
Prerequisites
- Bare Metal Servers: Ensure you have multiple physical servers available.
- Network Configuration: Ensure all servers are on the same network and can communicate with each other.
- Data Store: Kong Gateway requires a shared data store like PostgreSQL or Cassandra. Ensure you have a highly available setup for your data store.
- Load Balancer: A hardware or software load balancer to distribute traffic across Kong Gateway nodes.
Step-by-Step Guide
1. Install PostgreSQL for the Shared Data Store
- Install PostgreSQL:
sudo apt-get update
sudo apt-get install -y postgresql postgresql-contrib
- Configure PostgreSQL for High Availability:
- Set up replication between multiple PostgreSQL instances.
- Ensure that the primary and standby instances are configured correctly.
- Create a Kong Database:
sudo -u postgres psql
CREATE DATABASE kong;
CREATE USER kong WITH PASSWORD ‘yourpassword’;
GRANT ALL PRIVILEGES ON DATABASE kong TO kong;
\q
2. Install Kong Gateway on Each Server
- Install Kong Gateway:
sudo apt-get update
sudo apt-get install -y apt-transport-https
curl -s https://packages.konghq.com/keys/kong.key | sudo apt-key add –
echo “deb https://packages.konghq.com/debian/ $(lsb_release -sc) main” | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y kong
- Configure Kong Gateway:
- Create a kong.conf file on each server with the following configuration:
database = postgres
pg_host = <primary_postgresql_host>
pg_port = 5432
pg_user = kong
pg_password = yourpassword
pg_database = kong
- Start Kong Gateway:
kong migrations bootstrap
kong start
3. Configure Load Balancer
- Set Up a Load Balancer:
- Configure your load balancer to distribute traffic across the Kong Gateway nodes.
- Ensure the load balancer is set up for high availability (e.g., using a failover IP or DNS).
- Configure Health Checks:
- Configure health checks on the load balancer to monitor the health of each Kong Gateway node.
- Ensure that traffic is only sent to healthy nodes.
4. Set Up Failover Mechanism
- Database Failover:
- Ensure your PostgreSQL setup has a failover mechanism in place (e.g., using Patroni or pgpool-II).
- Kong Gateway Failover:
- Ensure that the load balancer can detect when a Kong Gateway node is down and redirect traffic to other nodes.
5. Implement Monitoring and Alerts
- Set Up Monitoring:
- Use tools like Prometheus and Grafana to monitor the health and performance of your Kong Gateway nodes and PostgreSQL database.
- Set Up Alerts:
- Configure alerts to notify you of any issues with the Kong Gateway nodes or the PostgreSQL database.
Example Configuration Files
PostgreSQL Configuration (pg_hba.conf):
# TYPE DATABASE USER ADDRESS METHOD
host kong kong 192.168.1.0/24 md5
Kong Gateway Configuration (kong.conf):
database = postgres
pg_host = 192.168.1.10
pg_port = 5432
pg_user = kong
pg_password = yourpassword
pg_database = kong
Summary
By following these steps, you can set up a highly available Kong Gateway on bare metal servers. This setup ensures that your API gateway remains reliable and performs well under various conditions. Make sure to thoroughly test your setup to ensure that failover and load balancing work as expected.