리스너
리스너 (Listeners)
리스너는 TCP 소켓에 연결되는 호스트명-포트 또는 IP-포트 조합을 말해요. Kong Event Gateway에서 리스너는 먼저 연결을 받은 뒤, 리스너 정책에 정의된 조건에 따라 TCP 연결을 가상 클러스터로 라우팅해요. TLS 서버 정책으로 암호화와 SNI 라우팅을 적용하거나, 가상 클러스터 전달 정책으로 연결을 특정 가상 클러스터로 보낼 수 있어요. 이 문서에서는 리스너의 개념과 Konnect API, Terraform, kongctl, UI를 활용한 설정 방법을 함께 살펴봐요
출처: 문서
본문
리스너란 무엇인가요?
리스너는 TCP 소켓에 연결되는 호스트명-포트 또는 IP-포트 조합을 나타내요. Forward to Virtual Cluster 정책에서 포트 매핑을 사용하는 경우, 리스너에는 백엔드 브로커 수만큼 최소한의 포트가 필요해요. SNI 라우팅의 경우, 포트가 하나뿐인 리스너 하나로 모든 브로커를 라우팅할 수 있어요. 포트는 단일 포트 또는 범위로 표현할 수 있어요. 주소는 IPv4, IPv6 또는 호스트명으로 지정할 수 있어요.
리스너에는 TLS 인증서를 강제하고 SNI 라우팅을 수행하는 정책을 둘 수 있어요. 리스너는 네트워크 스택의 4계층에서 동작해요. Kong Event Gateway에서 리스너는 먼저 연결을 받아들인 뒤, 리스너 정책에 정의된 조건에 따라 TCP 연결을 가상 클러스터로 라우팅해요.
flowchart LR
A[Kafka
client]
B[Listener
(TCP socket)
+ listener policies]
C@{ shape: processes, label: "Virtual clusters
+ consume, produce,
and cluster policies"}
D[Backend
cluster]
E[Kafka
cluster]
A --> B
subgraph id1 [Event Gateway]
B --> C
C --> D
end
D --> E
style B stroke:#86e2cc
style id1 rx:7,ry:7
리스너에는 TCP 연결 처리 방식을 정의하는 정책을 하나 이상 둘 수 있어요:
- TLS Server Policy: 암호화를 강제하고 인증서를 제공하며, SNI를 사용해 호스트명별로 연결을 라우팅할 수 있어요.
- Forward to Virtual Cluster Policy: 연결을 특정 가상 클러스터로 라우팅해요. 리스너당 포워드 정책은 하나만 허용돼요.
리스너 설정하기
Konnect API
리스너를 만들려면 Event Gateway API의 /listeners 엔드포인트를 호출하세요.
curl -X POST https://{region}.api.konghq.com/v1/event-gateways/{eventGatewayId}/listeners \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "listener-localhost",
"addresses": [
"0.0.0.0"
],
"ports": [
19092
]
}
'
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
-
region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요. -
KONNECT_TOKEN: Konnect 계정에 연결된 개인 액세스 토큰(PAT)이에요. -
virtualClusterId: Virtual Cluster의id예요. -
eventGatewayId: Event Gateway의id예요. -
eventGatewayListenerId: Event Gateway Listener의id예요.
리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Event Gateway API 레퍼런스를 확인하세요.
Terraform
사전 조건: 개인 액세스 토큰 설정하기
terraform {
required_providers {
konnect-beta = {
source = "kong/konnect-beta"
}
}
}
provider "konnect-beta" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Terraform 구성에 다음을 추가하세요:
resource "konnect_event_gateway_listener" "my_listener" {
provider = konnect-beta
addresses = ["0.0.0.0"]
ports = [19092]
gateway_id = konnect_event_gateway.my_event_gateway.id
}
kongctl
다음은 기본 구성으로 listener-localhost라는 새 리스너를 만들어요.
event_gateways:
- ref: eventGatewayName
name: eventGatewayName
listeners:
- ref: listener-localhost
name: listener-localhost
addresses:
- 0.0.0.0
ports:
- 19092
{: data-file="listener.yaml" data-tool="kongctl" }
다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:
eventGatewayName: Event Gateway의name이에요.
UI
다음은 기본 구성으로 listener-localhost라는 새 리스너를 만드는 방법이에요:
- Konnect에서 사이드바의 Event Gateway로 이동하세요.
- Event Gateway를 클릭하세요.
- Listeners 탭을 클릭하세요.
- New listener를 클릭하세요.
- Name 필드에
listener-localhost를 입력하세요. - Addresses 필드에
0.0.0.0을 입력하세요. - Ports 필드에
19092를 입력하세요. - Save and add policy next를 클릭하세요.
- Maybe later를 클릭해 정책 없이 리스너를 만드세요.
스키마
{
"description": "Listeners are used to expose virtual clusters to clients.",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier of the listener.",
"type": "string",
"format": "uuid"
},
"name": {
"description": "The unique name of the listener.",
"type": "string",
"maxLength": 255,
"minLength": 1,
"x-unicode-pattern": "^[\\p{L}\\p{N}][\\p{L}\\p{N} _\\-\\.:/+']*[\\p{L}\\p{N}]$"
},
"description": {
"description": "A human-readable description of the listener.",
"type": "string",
"default": "",
"maxLength": 512
},
"addresses": {
"$ref": "#/components/schemas/EventGatewayListenerAddresses"
},
"ports": {
"$ref": "#/components/schemas/EventGatewayListenerPorts"
},
"labels": {
"$ref": "#/components/schemas/Labels"
},
"created_at": {
"$ref": "#/components/schemas/CreatedAt"
},
"updated_at": {
"$ref": "#/components/schemas/UpdatedAt"
}
},
"additionalProperties": false,
"required": [
"id",
"name",
"addresses",
"ports",
"created_at",
"updated_at"
]
}
관련 리소스
더 알아보기 (Learn more)
- 리스너가 연결을 라우팅하는 가상 클러스터의 개념을 확인해 보세요 — virtual cluster
- 리스너에 적용할 수 있는 TLS 서버 정책과 가상 클러스터 전달 정책을 살펴 보세요 — listener policies
- 리스너를 생성할 때 호출하는
/listeners엔드포인트의 API 사용법을 확인해 보세요 —/listeners - Event Gateway에서 활용할 수 있는 다양한 정책을 탐색해 보세요 — Kong Event Gateway Policy Hub
- 포트 매핑 시 리스너 포트 수의 기준이 되는 백엔드 클러스터를 알아 보세요 — Backend clusters