Configure the Kong Gateway datastore on Linux
After installing the database, configure kong.conf
to connect to PostgreSQL,
run kong migrations bootstrap
to initialize the schema, then start Kong Gateway.
Prerequisites
Install PostgreSQL
Install PostgreSQL on Ubuntu using the following steps:
- Update the package list:
sudo apt update
- Install PostgreSQL:
sudo apt install -y postgresql postgresql-contrib
- Enable PostgreSQL to start on boot:
sudo systemctl enable postgresql
Configure environment variables
Set the following variables so that kong.conf
can interact with the datastore:
export KONG_DATABASE=postgres
export KONG_PG_HOST=127.0.0.1
export KONG_PG_PORT=5432
export KONG_PG_USER=kong
export KONG_PG_PASSWORD=super_secret
export KONG_PG_DATABASE=kong
Configure PostgreSQL
-
Switch to the default PostgreSQL user:
sudo -i -u postgres
-
Start the PostgreSQL shell:
psql
-
Create a
kong
user and password:CREATE USER kong WITH PASSWORD 'super_secret';
-
Create a database titled
kong
and assign the user as an owner:CREATE DATABASE kong OWNER kong;
-
Exit PostgreSQL, and exit the PostgreSQL shell:
exit
Run a Kong Gateway database migration
kong migrations
is used to configure the database for the first time.
Running bootstrap
forces Kong Gateway to bootstrap the database set up in the previous step and run all of the migrations:
kong migrations bootstrap
This command must be run as the root
user.
Validate
You can validate that the datastore was configured correctly by starting Kong Gateway.
-
Start Kong Gateway:
kong start
-
Verify the installation:
curl -i http://localhost:8001
If you receive a
200
status code, Kong Gateway was configured correctly.