OpenAPI 스펙 노출
OpenAPI 스펙 노출 (Kong Spec Expose)
이 문서는 Kong Gateway로 인증이 보호되는 업스트림 서비스의 OpenAPI 스펙을 외부에 노출하는 방법을 안내해요. Kong Spec Expose 플러그인을 사용하고, SPEC_URL 환경 변수에 노출하려는 OpenAPI 스펙의 URL을 지정하는 방식으로 설정해요. decK, Admin API, KIC, Terraform 등 다양한 도구로 플러그인을 전역 또는 서비스 단위로 구성하는 예시도 단계별로 소개해요
출처: 문서
본문
OpenAPI 스펙 노출하기 v1.0+
Kong Gateway가 인증으로 보호하는 업스트림 서비스의 OpenAPI 스펙을 노출해요.
사전 준비
- Kong Spec Expose 플러그인이 설치되어 있어요.
환경 변수
SPEC_URL: 노출할 OpenAPI 스펙의 URL이에요. 예를 들면https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v2.0/json/petstore.json과 같아요.
플러그인 설정하기
전역
decK
설정 파일인 kong.yaml에 다음 섹션을 추가해요:
_format_version: "3.0"
plugins:
- name: kong-spec-expose
config:
spec_url: ${{ env "DECK_SPEC_URL" }}
{: data-file="kong.yaml" data-tool="deck" }
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "kong-spec-expose",
"config": {
"spec_url": "'$SPEC_URL'"
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
spec_url: '$SPEC_URL'
plugin: kong-spec-expose
" | kubectl apply -f -
Terraform
사전 준비: Personal Access Token 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway Plugin을 생성하려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_kong_spec_expose" "my_kong_spec_expose" {
enabled = true
config = {
spec_url = var.spec_url
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
이 예제를 사용하려면 매니페스트에 다음 변수들을 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 실행 시점에 값을 지정할 수 있어요.
variable "spec_url" {
type = string
}
서비스
decK
설정 파일인 kong.yaml에 다음 섹션을 추가해요:
_format_version: "3.0"
plugins:
- name: kong-spec-expose
service: serviceName|Id
config:
spec_url: ${{ env "DECK_SPEC_URL" }}
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
serviceName|Id: 플러그인 설정의 대상이 될 서비스의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "kong-spec-expose",
"config": {
"spec_url": "'$SPEC_URL'"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
serviceName|Id: 플러그인 설정의 대상이 될 서비스의id또는name이에요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
spec_url: '$SPEC_URL'
plugin: kong-spec-expose
" | kubectl apply -f -
다음으로, service 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용해요:
kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=
Terraform
사전 준비: Personal Access Token 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway Plugin을 생성하려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_kong_spec_expose" "my_kong_spec_expose" {
enabled = true
config = {
spec_url = var.spec_url
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
이 예제를 사용하려면 매니페스트에 다음 변수들을 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 실행 시점에 값을 지정할 수 있어요.
variable "spec_url" {
type = string
}
라우트
decK
설정 파일인 kong.yaml에 다음 섹션을 추가해요:
_format_version: "3.0"
plugins:
- name: kong-spec-expose
route: routeName|Id
config:
spec_url: ${{ env "DECK_SPEC_URL" }}
{: data-file="kong.yaml" data-tool="deck" }
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
routeName|Id: 플러그인 설정의 대상이 될 라우트의id또는name이에요.
Admin API
다음 요청을 보내세요:
curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "kong-spec-expose",
"config": {
"spec_url": "'$SPEC_URL'"
}
}
'
다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:
routeName|Id: 플러그인 설정의 대상이 될 라우트의id또는name이에요.
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name:
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
spec_url: '$SPEC_URL'
plugin: kong-spec-expose
" | kubectl apply -f -
다음으로, httproute 또는 ingress 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용해요:
Gateway API
kubectl annotate -n kong httproute konghq.com/plugins=
Ingress
kubectl annotate -n kong ingress konghq.com/plugins=
Terraform
사전 준비: Personal Access Token 설정하기
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Konnect Gateway Plugin을 생성하려면 Terraform 설정에 다음 내용을 추가해요:
resource "konnect_gateway_plugin_kong_spec_expose" "my_kong_spec_expose" {
enabled = true
config = {
spec_url = var.spec_url
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
route = {
id = konnect_gateway_route.my_route.id
}
}
이 예제를 사용하려면 매니페스트에 다음 변수들을 추가해야 해요. TF_VAR_name=value 형식으로 설정하면 실행 시점에 값을 지정할 수 있어요.
variable "spec_url" {
type = string
}