Kong Gateway, Kong Manager 설치 및 구성하기
이 포스트에서는 VM 환경에서 Kong Gateway 를 설치/구성하고, Kong Gateway를 관리할 수 있는 대시보드를 설정하는 방법에 대해 다룹니다.
이 포스트에서는 Ubuntu 24.04 LTS 환경에서 Kong Gateway 3.6.1버전으로 진행했습니다.
목차
1. Kong Gateway란?
2. Kong Gateway 설치하기
3. 데이터 저장소 설정하기
3-1. DB와 연동 설정
3-2. YAML파일 사용 설정(DB-less)
4. Kong Gateway 대시보드(Kong Manager) 설정하기
1. Kong Gateway란?

Kong Gateway는 NGINX를 기반으로 한 API Gateway입니다. Kong Gateway는 공식적으로 지원하는 Kong Manager 대시보드를 통해서 간편하게 설정들을 확인하고, DB mode의 경우 Kong Manager을 통해서 설정들을 추가하고 관리할 수 있습니다.
Kong Gateway의 가장 큰 특징 중 하나는 Lua, Go, JavaScript, Python과 같은 다양한 언어로 작성할 수 있는 플러그인을 통한 기능 확장입니다. Kong에서 제공하는 기본 플러그인으로 rate limiting, proxy caching, 인증과 같은 기능을 사용할 수 있고, 자체적으로 개발한 플러그인을 적용할 수도 있습니다.
2. Kong Gateway 설치하기
Kong APT 저장소를 이용해서 패키지 설치를 진행하도록 하겠습니다. APT 저장소 정보에 변동이 있을 경우 공식 페이지를 참고하세요.
1. Kong APT 저장소를 설정합니다.
$ curl -1sLf "https://packages.konghq.com/public/gateway-36/gpg.1D935A6039ECFC53.key" | gpg --dearmor | sudo tee /usr/share/keyrings/kong-gateway-36-archive-keyring.gpg > /dev/null
$ curl -1sLf "https://packages.konghq.com/public/gateway-36/config.deb.txt?distro=ubuntu&codename=jammy" | sudo tee /etc/apt/sources.list.d/kong-gateway-36.list > /dev/null
2. 저장소를 업데이트합니다.
$ sudo apt-get update
3. Kong을 설치합니다.
$ sudo apt-get install -y kong=3.6.1
4. /etc/kong 경로에서 설정 파일을 확인할 수 있습니다.
$ ls /etc/kong
kong.conf.default kong.logrotate
3. 데이터 저장소 설정하기
Kong Gateway는 설정을 DB와 연동하여 관리하는 방법과, DB를 사용하지 않고 yaml 파일로 관리하는 방법(DB-less)을 지원합니다.
3-1. DB와 연동 설정
Kong Gateway는 설정파일 저장을 위한 데이터베이스로 PostgreSQL을 공식적으로 지원합니다. PostgreSQl DB를 구성하여 Kong Gateway와 연동하도록 하겠습니다.
1. PostgreSQL을 설치합니다.
$ sudo apt install postgresql
2. PostgreSQL 마스터 사용자로 사용자를 변경하고, 데이터베이스에 로그인합니다.
$ sudo -i -u postgres
$ psql
3. Kong Gateway에 사용될 유저와, 데이터베이스를 생성합니다.
postgres=# CREATE USER kong WITH PASSWORD '<지정 비밀번호>'; CREATE DATABASE kong OWNER kong;
4. 명령어를 통해 생성된 유저와 데이터베이스를 확인할 수 있습니다.
postgres=# \du
List of roles
Role name | Attributes
-----------+------------------------------------------------------------
kong |
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
kong | kong | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
postgres | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
......
5. 설정한 데이터베이스를 Kong Gateway와 연동하기 위해, kong.conf 파일을 수정합니다.
기본 설치시에 생성된 kong.conf.default 파일을 kong.conf 파일로 복사하여 사용했습니다.
$ sudo vi /etc/kong/kong.conf
------
...
database = postgres # Determines the database (or no database) for
# this node
# Accepted values are `postgres` and `off`.
pg_host = 127.0.0.1 # Host of the Postgres server.
pg_port = 5432 # Port of the Postgres server.
pg_timeout = 5000 # Defines the timeout (in ms), for connecting,
# reading and writing.
pg_user = kong # Postgres user.
pg_password = <지정 비밀번호> # Postgres user's password.
pg_database = kong
kong.conf 파일에 database 설정의 주석 처리를 해제하고 앞서 구성한 DB설정을 입력합니다.
PostgreSQL의 설정을 변경했다면 해당 내용으로 수정합니다.
6. 명령어를 통해 데이터 베이스를 설정합니다.
$ kong migrations bootstrap -c /etc/kong/kong.conf
Bootstrapping database...
migrating core on database 'kong'...
......
Database is up-to-date
7. 데이터베이스에 접속해 테이블을 확인할 수 있습니다.
$ psql -h localhost -U kong -d kong # localhost kong 사용자의 kong DB 접속
kong=> \dt
List of relations
Schema | Name | Type | Owner
--------+-------------------------------+-------+-------
public | acls | table | kong
public | acme_storage | table | kong
public | basicauth_credentials | table | kong
public | ca_certificates | table | kong
public | certificates | table | kong
public | cluster_events | table | kong
public | clustering_data_planes | table | kong
public | consumers | table | kong
public | filter_chains | table | kong
public | hmacauth_credentials | table | kong
public | jwt_secrets | table | kong
public | key_sets | table | kong
public | keyauth_credentials | table | kong
public | keys | table | kong
public | locks | table | kong
public | oauth2_authorization_codes | table | kong
public | oauth2_credentials | table | kong
public | oauth2_tokens | table | kong
public | parameters | table | kong
public | plugins | table | kong
public | ratelimiting_metrics | table | kong
public | response_ratelimiting_metrics | table | kong
public | routes | table | kong
public | schema_meta | table | kong
public | services | table | kong
public | sessions | table | kong
public | sm_vaults | table | kong
public | snis | table | kong
public | tags | table | kong
public | targets | table | kong
public | upstreams | table | kong
public | workspaces | table | kong
(32 rows)
8. Kong Gateway를 실행합니다.
$ sudo kong start -c /etc/kong/kong.conf
Kong started
9. 8001번 포트 연결로 Kong의 실행을 확인할 수 있습니다.
$ curl -I http://localhost:8001
HTTP/1.1 200 OK
Date: Thu, 23 May 2024 06:29:12 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Length: 15837
X-Kong-Admin-Latency: 21
Server: kong/3.6.1
3-2. YAML파일 사용 설정(DB-less)
Kong Gateway를 DB와 연동하지 않고, yaml 파일을 통해 설정을 관리하도록 설정할 수 있습니다.
1. kong.yml 파일을 생성합니다.
$ cd /etc/kong
$ kong config init # 샘플 kong.yml 파일 생성
$ ls
kong.conf.default kong.logrotate kong.yml
생성된 샘플 파일인 kong.yml 파일은 다음과 같습니다.
# ------------------------------------------------------------------------------
# This is an example file to get you started with using
# declarative configuration in Kong.
# ------------------------------------------------------------------------------
# Metadata fields start with an underscore (_)
# Fields that do not start with an underscore represent Kong entities and attributes
# _format_version is mandatory,
# it specifies the minimum version of Kong that supports the format
_format_version: "3.0"
# _transform is optional, defaulting to true.
# It specifies whether schema transformations should be applied when importing this file
# as a rule of thumb, leave this setting to true if you are importing credentials
# with plain passwords, which need to be encrypted/hashed before storing on the database.
# On the other hand, if you are reimporting a database with passwords already encrypted/hashed,
# set it to false.
_transform: true
# Custom annotations can be added via _comment and _ignore fields. The comments
# must be strings, and the ignored fields must be an array, carrying any type as
# values. _comment and _ignore fields can appear at the top level of the file
# and at the top level of any entity.
_comment: This is a top level comment, and must be a string
_ignore:
- This array entry will be ignored
- as well as this one
...
필수적으로 설정되어야 할 _format_version 및 구성 설명과, 구성 예제가 주석처리되어있습니다.
2. kong.conf.default 파일을 복사하여 생성한 kong.conf 파일을 수정합니다.
kong.conf.default 파일은 백업을 위해 남겨두고, kong.conf파일을 통해 설정을 진행했습니다.
$ sudo cp kong.conf.default kong.conf
$ sudo vi /etc/kong/kong.conf
------
...
database = off
...
declarative_config = /etc/kong/kong.yml
...
DB-less 방식의 구성이기때문에, database 설정을 off로 설정하고, declarative_config 설정을 1번에서 생성한 kong.yml 파일의 경로로 설정합니다.
3. Kong Gateway를 실행합니다.
$ sudo kong start -c /etc/kong/kong.conf
Kong started
4. 8001번 포트 연결로 Kong의 실행을 확인할 수 있습니다.
$ curl -I http://localhost:8001
HTTP/1.1 200 OK
Date: Thu, 23 May 2024 07:07:06 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Length: 15959
X-Kong-Admin-Latency: 5
Server: kong/3.6.1
4. Kong Gateway 대시보드(Kong Manager) 설정하기
Kong Manager는 Kong Gateway에서 공식적으로 지원하는 대시보드입니다. Kong Manager를 통해 Kong Gateway의 구성을 쉽게 확인하고, 생성 및 관리할 수 있습니다.
1. 대시보드 설정을 위해 kong.conf 파일을 수정합니다.
$ sudo vi /etc/kong/kong.conf
------
...
admin_listen = 0.0.0.0:8001 reuseport backlog=16384, 0.0.0.0:8444 http2 ssl reuseport backlog=16384
...
admin_gui_url = http://192.168.***.***:8002/manager # IP 설정
admin_gui_path = /manager
외부에서 대시보드에 엑세스하기 위해 Kong Gateway가 실행중인 VM의 IP를 설정했습니다.
2. 변경된 설정을 적용합니다.
$ sudo kong restart -c /etc/kong/kong.conf
Kong stopped
Kong started
3. 설정한 url로 접속하여 대시보드 구성을 확인합니다.


DB와 함께 구성한 경우 Datastore 항목에 관련 정보가 포함되어 표시됩니다.
댓글을 달려면 로그인해야 합니다.