Dev Portal로 API 패키징하기
Dev Portal로 API 패키징하기 (Package APIs with Dev Portal)
이 문서에서는 Kong Konnect에서 Dev Portal을 통해 API 패키지를 만드는 방법을 알려드려요 기존 API에 OpenAPI 스펙을 첨부하고 ACE 플러그인을 적용한 후 컨트롤 플레인을 연결하여 개발자가 사용할 수 있도록 해요 그런 다음 API 패키지를 생성하고 요금 제한을 설정한 뒤 Dev Portal에 게시하는 전체 과정을 배울 수 있어요
출처: 문서
본문
요약
기존 Dev Portal API에서 API 패키지를 어떻게 생성하나요? API 패키징은 다음 단계를 포함해요:
- API를 생성하고 OpenAPI 스펙을 첨부하세요.
- 연결하려는 컨트롤 플레인에 Access Control Enforcement (ACE) 플러그인을 전역적으로 적용하세요.
- 개발자가 사용할 수 있도록 컨트롤 플레인을 API에 연결하세요.
- 작업과 패키지 속도 제한을 추가하여 API 패키지를 생성하세요.
- API 패키지를 Dev Portal에 게시하세요.
전제 조건
Kong Konnect
이 튜토리얼은 Konnect 튜토리얼이고 Konnect 개인 액세스 토큰이 필요해요.
-
Konnect PAT 페이지를 열고 Generate Token을 선택하여 새 개인 액세스 토큰을 생성하세요.
-
토큰을 환경 변수로 내보내세요:
export KONNECT_TOKEN='YOUR_KONNECT_PAT' -
퀵스타트 스크립트를 실행하여 컨트롤 플레인과 데이터 플레인을 자동으로 프로비저닝하고 환경을 구성하세요:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN \ --deck-output이렇게 하면
quickstart라는 Konnect 컨트롤 플레인이 설정되고 로컬 데이터 플레인이 프로비저닝되며 다음 환경 변수 내보내기가 출력돼요:export DECK_KONNECT_TOKEN=$KONNECT_TOKEN export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart export DECK_KONNECT_ADDR=https://us.api.konghq.com export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='http://localhost:8000'이 내용을 복사하여 터미널에 붙여넣어 세션을 구성하세요.
decK v1.68.0+
이 튜토리얼을 완료하려면 decK을 설치해요. decK를 최신 버전(1.68.0)으로 유지하는 것이 좋아요.
decK는 상태 파일로 Kong Gateway를 선언적으로 관리하기 위한 CLI 도구예요.
이 가이드는 deck gateway apply를 사용하며, 게이트웨이 인스턴스에 엔티티 구성을 직접 적용해요.
현재 decK 버전은 deck version으로 확인할 수 있어요.
Konnect roles
API 패키지를 생성하려면 다음 역할이 필요해요:
- API에 대한 편집자 역할
- API 및 API 패키지에 대한 게시자 역할
- API 생성자
Dev Portal
이 튜토리얼을 위해 미리 구성된 Dev Portal이 필요해요. 아직 이러한 설정이 구성되지 않은 경우 다음 단계에 따라 미리 구성하세요:
- Konnect 사이드바에서 Dev Portal을 확장하세요.
- Portals를 클릭하세요.
- New portal을 클릭하세요.
- Dev Portal의 이름을 입력하세요.
- Create and continue를 클릭하세요.
- Dev Portal의 모양을 사용자 지정하세요.
- Save를 클릭하세요.
Dev Portal APIs
이 가이드를 완료하려면 카탈로그에 API가 필요해요:
-
Konnect 사이드바에서 Catalog를 클릭하세요.
-
APIs 탭을 클릭하세요.
Catalog Classic을 사용하는 경우 사이드바에서 APIs를 클릭하세요.
-
New API를 클릭하세요.
-
API name 필드에
MyAPI를 입력하세요. -
Create를 클릭하세요.
Required entities
이 튜토리얼을 위해 Gateway Service 및 Route와 같은 Kong Gateway 엔티티가 미리 구성되어 있어야 해요. 이러한 엔티티는 Kong Gateway가 작동하는 데 필수적이지만, 설치하는 것이 이 가이드의 주요 내용은 아니에요.
-
다음 명령을 실행하세요:
echo ' _format_version: "3.0" services: - name: example-service url: http://httpbin.konghq.com/anything routes: - name: example-route paths: - "/anything" methods: - GET - PUT - POST - PATCH - DELETE service: name: example-service protocols: - http - https ' | deck gateway apply -엔티티에 대한 자세한 내용은 엔티티 문서를 참조하세요.
API specification
이 가이드를 완료하려면 생성한 Route와 일치하는 API 스펙이 필요해요. Catalog는 스펙을 사용하여 API 패키지에 작업을 추가해요.
cat > example-api-spec.yaml << 'EOF'
openapi: 3.0.0
info:
title: Example API
description: Example API service for testing and documentation
version: 1.0.0
servers:
- url: http://httpbin.konghq.com
description: Backend service (HTTP only, port 80)
paths:
/anything:
get:
summary: Get anything
description: Echo back GET request details
operationId: getAnything
tags:
- Echo
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/EchoResponse'
'426':
description: Upgrade Required (HTTPS redirect)
post:
summary: Post anything
description: Echo back POST request details
operationId: postAnything
tags:
- Echo
requestBody:
content:
application/json:
schema:
type: object
additionalProperties: true
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/EchoResponse'
'426':
description: Upgrade Required (HTTPS redirect)
put:
summary: Put anything
description: Echo back PUT request details
operationId: putAnything
tags:
- Echo
requestBody:
content:
application/json:
schema:
type: object
additionalProperties: true
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/EchoResponse'
'426':
description: Upgrade Required (HTTPS redirect)
patch:
summary: Patch anything
description: Echo back PATCH request details
operationId: patchAnything
tags:
- Echo
requestBody:
content:
application/json:
schema:
type: object
additionalProperties: true
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/EchoResponse'
'426':
description: Upgrade Required (HTTPS redirect)
delete:
summary: Delete anything
description: Echo back DELETE request details
operationId: deleteAnything
tags:
- Echo
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/EchoResponse'
'426':
description: Upgrade Required (HTTPS redirect)
components:
schemas:
EchoResponse:
type: object
properties:
args:
type: object
description: Query parameters
data:
type: string
description: Request body data
files:
type: object
description: Uploaded files
form:
type: object
description: Form data
headers:
type: object
description: Request headers
json:
type: object
description: JSON request body
method:
type: string
description: HTTP method used
origin:
type: string
description: Origin IP address
url:
type: string
description: Request URL
x-kong-service:
name: example-service
host: httpbin.konghq.com
port: 80
protocol: http
path: /anything
retries: 5
connect_timeout: 60000
write_timeout: 60000
read_timeout: 60000
x-kong-route:
name: example-route
protocols: [http, https]
methods: [GET, POST, PUT, PATCH, DELETE]
paths: [/anything]
strip_path: true
preserve_host: false
https_redirect_status_code: 426
EOF
API 패키지를 Dev Portal의 기존 API로 구성할 수 있어요. API 패키지를 사용하면 다음을 할 수 있어요:
- 기존 API 작업을 기반으로 특정 사용 사례나 파트너를 위한 별도의 API를 생성할 수 있어요.
- 개발자 셀프 서비스 및 애플리케이션 등록을 위해 여러 Gateway Service 및/또는 Route에 연결할 수 있어요.
- API 패키지 또는 작업별로 속도 제한 정책을 적용할 수 있어요.
- 특정 개발자 및 팀에 대한 역할 기반 액세스 제어를 관리할 수 있어요.
Associate a control plane
개발자가 API를 사용할 수 있도록 하려면 먼저 API 게이트웨이와 컨트롤 플레인을 API에 연결해야 해요.
API의 OpenAPI 스펙에서 가져온 작업은 Route와 겹쳐야 요청이 올바른 Service로 라우팅돼요. 게이트웨이 라우팅 구성은 작업을 추가해도 직접 수정되지 않아요.
-
Konnect 사이드바에서 Catalog를 클릭하세요.
Catalog Classic을 사용하는 경우 사이드바에서 APIs를 클릭하세요.
-
MyAPI를 클릭하세요.
-
Gateway 탭을 클릭하세요.
-
Link gateway를 클릭하세요.
-
Control plane 드롭다운 메뉴에서 "quickstart"를 선택하세요.
-
Link to a control plane을 선택하세요.
-
Add the Access Control and Enforcement plugin 설정에서 Add plugin을 클릭하세요.
-
Link gateway를 클릭하세요.
-
API Specification 탭을 클릭하세요.
-
Upload Spec을 클릭하세요.
-
Select file을 클릭하세요.
-
example-api-spec.yaml을 선택하세요. -
Save를 클릭하세요.
Assign operations to API packages
이제 API에서 작업을 선택하여 API 패키지를 생성할 수 있어요. 작업은 API의 OpenAPI 스펙을 사용하여 Route에 자동으로 매핑돼요. 게이트웨이 구성은 직접 수정되지 않으므로 일치하지 않는 작업은 사용자가 작업을 수행하기 위해 API 게이트웨이 권한이 필요함을 나타내기 위해 강조 표시돼요.
-
Konnect 사이드바에서 Catalog를 클릭하세요.
-
New 드롭다운 메뉴에서 "API package"를 선택하세요.
Catalog Classic을 사용하는 경우 사이드바에서 API packages를 클릭하세요.
-
API package name 필드에
Company package를 입력하세요. -
Package rate limit을 활성화하세요.
-
속도 제한에
5를 입력하고 "Minute"을 선택하세요. -
API operations 설정에서 Add operations from APIs를 클릭하세요.
-
Add API operations 창에서 MyAPI를 클릭하세요.
-
GET
/anything에 대해 Add를 클릭하세요. -
PUT
/anything에 대해 Add를 클릭하세요. -
POST
/anything에 대해 Add를 클릭하세요. -
Add API operations 창을 종료하세요.
-
Create API package를 클릭하세요.
-
Specifications 탭을 클릭하세요.
-
Generate spec from operations를 클릭하세요.
-
Save를 클릭하세요.
Publish API packages to Dev Portal
이제 API 패키지를 Dev Portal에 게시하여 개발자가 사용할 수 있도록 할 수 있어요.
-
Konnect 사이드바에서 Catalog를 클릭하세요.
-
API packages 탭을 클릭하세요.
Catalog Classic을 사용하는 경우 사이드바에서 API packages를 클릭하세요.
-
Company package를 클릭하세요.
-
Publish API를 클릭하세요.
-
Portal 드롭다운 메뉴에서 Dev Portal을 선택하세요.
-
Authentication strategy 드롭다운 메뉴에서 "Disabled"를 선택하세요.
-
Public을 클릭하세요.
-
Publish API를 클릭하세요.
API 패키지가 이제 Dev Portal에 게시돼요. 게시된 API 패키지는 Dev Portal에서 게시된 API와 동일하게 표시되며, 둘 다 개발자가 애플리케이션을 등록할 수 있어요.
Validate
이제 API 패키지를 게시했으므로 Dev Portal의 URL로 이동하여 성공적으로 게시되었는지 확인할 수 있어요. Dev Portal의 URL은 Konnect UI의 Dev Portal 개요로 이동하여 찾을 수 있어요.
Cleanup
Clean up Konnect environment
새 컨트롤 플레인을 생성했고 무료 평가판 크레딧을 절약하거나 불필요한 요금을 피하려면 이 튜토리얼에서 사용한 새 컨트롤 플레인을 삭제하세요.
Related Resources
더 알아보기 (Learn more)
- API 패키지 생성 및 관리에 대한 자세한 문서 — API packages
- Dev Portal의 개요와 기능 살펴보기 — Dev Portal overview
- Dev Portal에 대한 상세 안내 — About Dev Portal
- 컨트롤 플레인 관리 페이지 — control plane
- decK CLI 도구 설치 및 사용법 — decK
- Konnect 팀과 역할에 대한 문서 — roles