Prerequisites
Ensure your system meets the following requirements before installation:
- Ubuntu 24.04 LTS (64-bit) (used for this installation procedure)
Launch an EC2 Instance for Kong:
1. Go to the AWS Management Console.
2. Launch a new EC2 instance (e.g., Ubuntu 22.04 LTS).
3. Assign a public IP address and ensure the instance is in the same VPC as your load balancer.
4. Open the necessary ports in the EC2 security group:
1. Port 8000 (HTTP traffic to Kong)
2. Port 8443 (HTTPS traffic to Kong)
3. Port 8001 (Admin API, optional and restrict access for security)
4. Port 22 ssh connection
Post installation installing dependencies of Kong:
> sudo apt-get install openssl procps perl libpcre3
If <libpcre3> is not available follow the below steps:
>sudo apt update
>sudo apt install -y libpcre3
If not installed search for this using below shared command
>apt-cache search libpcre3
>sudo add-apt-repository universe (this is to add the universe repo to fetch the missing depeden cy.)
>sudo apt update
Step 1: Download and Install Kong Gateway
Run the following command to download the Kong Gateway 3.9 package:
>curl -Lo kong-3.9.0.deb “https://packages.konghq.com/public/gateway-39/deb/ubuntu/pool/noble/main/k/ko/kong_3.9.0/kong_3.9.0_$(dpkg –print-architecture).deb”
Once downloaded, install Kong Gateway using:
>sudo apt install -y ./kong-3.9.0.deb
Step 2: Configure Kong
Initialize the default Kong configuration:
>sudo kong config init
Increase the open file limit (recommended for production use):
>ulimit -n 4096
Step 3: Install and Configure PostgreSQL
Kong requires a database to store its configurations. Install PostgreSQL using:
>sudo apt update
>sudo apt install postgresql -y
Ubuntu includes PostgreSQL by default. To install it, open a terminal and run:
>sudo apt update
>sudo apt install postgresql
Start and enable PostgreSQL:
>sudo systemctl start postgresql
>sudo systemctl enable postgresql
Switch to the PostgreSQL user:
>sudo passwd postgres
> add the custom passwd for this user
Eg: admin123
>sudo -i -u postgres
Access the PostgreSQL prompt:
>psql
Create a database and user for Kong:
>CREATE USER kong WITH PASSWORD ‘your_secure_password’;
>CREATE DATABASE kong OWNER kong;
Replace ‘your_secure_password’ with a strong password of your choice.
Exit the PostgreSQL prompt:
>\q
Return to your regular user:
>exit
Step 4: Configure Kong with PostgreSQL
Copy the default configuration file for Kong:
>sudo cp /etc/kong/kong.conf.default /etc/kong/kong.conf
Edit the configuration file:
>Sudo vi /etc/kong/kong.conf
Modify the database settings in kong.conf to use PostgreSQL:
database = postgres
pg_host = 127.0.0.1
pg_port = 5432
pg_user = kong
pg_password = <your_password>
pg_database = kong
Step 5: Run Database Migrations
Bootstrap the Kong database:
>kong migrations bootstrap -c /etc/kong/kong.conf
Step 6: Start Kong Gateway
Start Kong using:
>kong start -c /etc/kong/kong.conf
Step:7 Verify Kong is running:
>curl -i http://localhost:8001
If Kong is running, you should see an HTTP response with status 200 OK.
If everything is configured correctly, Kong Gateway should be up and running.
Testing by creating a Service
Step 8: Create a Service that forwards traffic to simple API
Run this command to create a service:
>curl -i -X POST http://localhost:8001/services/ \
–data “name=my-service” \
–data “url=http://httpbin.org”
This creates a service named my-service that forwards requests to http://httpbin.org.
REF! OUTPUT:
{
“name”: “my-service”,
“id”: “service_id”,
“created_at”: 1234567890,
“updated_at”: 1234567890,
“url”: “http://httpbin.org”
}
Step 9: Create a Route for the Service
This tells Kong which URL path to match and forward to your service.
For example, to create a route for /my-api:
>curl -i -X POST http://localhost:8001/services/my-service/routes \
–data “paths[]=/my-api”
This will route requests from http://localhost:8000/my-api to the my-service service.
Step 10: Test the Route
Once the service and route are set up, you can test it by sending a request to the route you just
>curl -i http://localhost:8000/my-api
You should get a response from http://httpbin.org, showing that Kong is properly forwarding the request.
Step 11: Verify the Service and Route
If you want to check that the service and route are created correctly, you can list them:
List services:
>curl -i http://localhost:8001/services
List routes:
>curl -i http://localhost:8001/routes
These commands should show the my-service and the /my-api route that you created.