TLSRoute와 SNI로 Kong Event Gateway 배포
TLSRoute와 SNI로 Kong Event Gateway 배포 (Deploy Kong Event Gateway with TLSRoute and SNI)
이 문서에서는 Kong Event Gateway를 프로덕션 지향 토폴로지로 배포하는 방법을 소개해요. Kubernetes Gateway와 TLSRoute로 Event Gateway를 구성하고, Kubernetes Gateway에서는 TLS를 패스스루한 다음 Event Gateway에서 TLS를 종단 처리해요. 그리고 SNI를 활용해 단일 TLS 리스너 하나로 가상 클러스터 트래픽을 라우팅하는 과정을 단계별로 따라 해 봐요
출처: 문서
본문
TL;DR
프로덕션 지향 토폴로지에서는 Kong Event Gateway를 어떻게 배포하나요?
Event Gateway 앞을 Gateway와 TLSRoute로 구성하고, TLS 종료는 Event Gateway에서 처리하며, SNI로 가상 클러스터를 라우팅해요.
사전 준비
시리즈 사전 준비
이 페이지는 Kubernetes에 Kong Event Gateway 배포 시리즈의 일부예요.
이 페이지를 진행하기 전에 이전 페이지인 포트 매핑으로 Kong Event Gateway 배포를 먼저 완료하세요.
이 배포 패턴은 Kubernetes 엣지에서 단일 TLS 리스너를 사용하고, Kong Event Gateway 내부에서는 SNI로 Kafka 트래픽을 라우팅해요.
다음과 같은 경우에 이 패턴을 사용하세요:
- 공개 Kafka 리스너 하나
- Kubernetes
Gateway에서의 TLS 패스스루 - 단일 포트에서 DNS 이름으로 광고되는 브로커 메타데이터
GatewayConfiguration 및 GatewayClass 생성
TLSRoute 예제에서 사용할 managed Gateway 클래스를 생성해요. 이 Gateway는 Konnect를 통해 프로비저닝되기 때문에, GatewayConfiguration은 사전 준비에서 생성한 KonnectAPIAuthConfiguration을 참조해야 해요.
-
GatewayConfiguration과GatewayClass리소스를 생성해요:echo ' apiVersion: gateway-operator.konghq.com/v2beta1 kind: GatewayConfiguration metadata: name: kong-configuration namespace: kong spec: konnect: authRef: name: konnect-api-auth dataPlaneOptions: deployment: podTemplateSpec: spec: containers: - name: proxy image: kong/kong-gateway:3.16 --- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: name: kong spec: controllerName: konghq.com/gateway-operator parametersRef: group: gateway-operator.konghq.com kind: GatewayConfiguration name: kong-configuration namespace: kong ' | kubectl apply -f - -
GatewayClass가 수락될 때까지 기다려요:kubectl wait gatewayclass/kong \ --for=condition=Accepted=True \ --timeout=5m
두 번째 KonnectEventGateway 생성
이 가이드는 portMapping 예제와 함께 실행될 수 있도록 별도의 컨트롤 플레인을 사용해요.
-
KonnectEventGateway리소스를 생성해요:echo ' apiVersion: konnect.konghq.com/v1alpha1 kind: KonnectEventGateway metadata: name: cp-event-tls namespace: kong spec: apiSpec: name: cp-event-tls description: Event Gateway control plane for TLSRoute and SNI konnect: authRef: name: konnect-api-auth ' | kubectl apply -f - -
리소스가 준비될 때까지 기다려요:
kubectl wait konnecteventgateway/cp-event-tls -n kong \ --for=condition=Programmed=True \ --timeout=10m
백엔드 클러스터, 가상 클러스터, 리스너 생성
-
Kafka 트래픽이
cp-event-tls컨트롤 플레인을 통해 연결되는 방식을 정의하는EventGatewayBackendCluster,EventGatewayVirtualCluster,EventGatewayListener를 생성해요:echo ' apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayBackendCluster metadata: name: default-backend-cluster-tls namespace: kong spec: gatewayRef: type: namespacedRef namespacedRef: name: cp-event-tls apiSpec: name: default_backend_cluster_tls bootstrapServers: - kafka-cluster.kafka.svc.cluster.local:9092 authentication: type: anonymous anonymous: {} insecureAllowAnonymousVirtualClusterAuth: Enabled tls: enabled: Disabled --- apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayVirtualCluster metadata: name: example-virtual-cluster-tls namespace: kong spec: eventGatewayBackendClusterRef: type: namespacedRef namespacedRef: name: default-backend-cluster-tls apiSpec: name: example_virtual_cluster_tls dnsLabel: vc-tls-1 aclMode: passthrough authentication: - type: anonymous namespace: prefix: "vctls_" mode: hide_prefix --- apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayListener metadata: name: sni-listener namespace: kong spec: apiSpec: name: sni_listener addresses: - 0.0.0.0 ports: - "9092" gatewayRef: type: namespacedRef namespacedRef: name: cp-event-tls ' | kubectl apply -f - -
리소스들이 준비될 때까지 기다려요:
kubectl wait eventgatewaybackendcluster/default-backend-cluster-tls -n kong \ --for=condition=Programmed=True \ --timeout=10m kubectl wait eventgatewayvirtualcluster/example-virtual-cluster-tls -n kong \ --for=condition=Programmed=True \ --timeout=10m kubectl wait eventgatewaylistener/sni-listener -n kong \ --for=condition=Programmed=True \ --timeout=10m
TLS Secret 및 리스너 정책 생성
-
*.keg.test.local에 대한 자체 서명 TLS 인증서를 생성해요. 이 와일드카드는 이 리스너의 모든 가상 클러스터에 걸친 브로커 및 부트스트랩 호스트명을 모두 커버해요:openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout tls.key -out tls.crt \ -subj "/CN=keg.test.local" \ -addext "subjectAltName=DNS:*.keg.test.local" -
인증서와 키를 base64로 인코딩한 환경 변수로 내보내요:
export TLS_CRT=$(cat tls.crt | base64) export TLS_KEY=$(cat tls.key | base64) -
TLS Secret을 생성해요:
echo ' apiVersion: v1 kind: Secret metadata: name: sni-listener-tls namespace: kong labels: konghq.com/secret: "true" type: kubernetes.io/tls data: tls.crt: '"$TLS_CRT"' tls.key: '"$TLS_KEY"' ' | kubectl apply -f - -
리스너 정책을 적용해요:
echo ' apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayListenerPolicy metadata: name: sni-tls-server namespace: kong spec: apiSpec: type: tlsServer tlsServer: name: tls_server enabled: Enabled config: allowPlaintext: Disabled versions: min: TLSv1.2 max: TLSv1.3 certificates: - certificate: type: secretRef secretRef: name: sni-listener-tls key: type: secretRef secretRef: name: sni-listener-tls eventGatewayListenerRef: type: namespacedRef namespacedRef: name: sni-listener --- apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayListenerPolicy metadata: name: sni-forward namespace: kong spec: apiSpec: type: forwardToVirtualCluster forwardToVirtualCluster: name: forward_sni config: type: sni sni: sniSuffix: ".keg.test.local" brokerHostFormat: type: per_cluster_suffix advertisedPort: 9092 eventGatewayListenerRef: type: namespacedRef namespacedRef: name: sni-listener ' | kubectl apply -f - -
리스너 정책이 준비될 때까지 기다려요:
kubectl wait eventgatewaylistenerpolicy/sni-tls-server -n kong \ --for=condition=Programmed=True \ --timeout=10m kubectl wait eventgatewaylistenerpolicy/sni-forward -n kong \ --for=condition=Programmed=True \ --timeout=10m
컨슈(consume) 및 프로듀스(produce) 정책 생성
이 정책들은 컨슈 및 프로듀스되는 레코드에 마커 헤더를 추가해서, 정책이 실제로 적용됐는지 확인할 수 있게 해줘요.
-
컨슈 및 프로듀스 정책을 생성해요:
echo ' apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayVirtualClusterConsumePolicy metadata: name: example-virtual-cluster-tls-consume-policy namespace: kong spec: eventGatewayVirtualClusterRef: type: namespacedRef namespacedRef: name: example-virtual-cluster-tls apiSpec: type: modifyHeaders modifyHeaders: name: example_tls_consume_policy description: Add a marker header to consumed records for the TLSRoute example config: actions: - op: set set: key: x-kong-consume-policy value: tlsroute --- apiVersion: configuration.konghq.com/v1alpha1 kind: EventGatewayVirtualClusterProducePolicy metadata: name: example-virtual-cluster-tls-produce-policy namespace: kong spec: eventGatewayVirtualClusterRef: type: namespacedRef namespacedRef: name: example-virtual-cluster-tls apiSpec: type: modifyHeaders modifyHeaders: name: example_tls_produce_policy description: Add a marker header to produced records for the TLSRoute example config: actions: - op: set set: key: x-kong-produce-policy value: tlsroute ' | kubectl apply -f - -
리소스들이 준비될 때까지 기다려요:
kubectl wait eventgatewayvirtualclusterconsumepolicy/example-virtual-cluster-tls-consume-policy -n kong \ --for=condition=Programmed=True \ --timeout=10m kubectl wait eventgatewayvirtualclusterproducepolicy/example-virtual-cluster-tls-produce-policy -n kong \ --for=condition=Programmed=True \ --timeout=10m
KegDataPlane 배포
TLSRoute 패턴에서는 KegDataPlane이 클러스터 내부에 유지돼요. Kubernetes Gateway가 공개 엔트리포인트 역할을 하기 때문에, Kafka 리스너는 ClusterIP Service로 노출돼요.
KegDataPlane을 배포해요:
echo '
apiVersion: eventgateway.konghq.com/v1alpha1
kind: KegDataPlane
metadata:
name: keg-tls-dp
namespace: kong
spec:
controlPlaneRef:
type: konnectNamespacedRef
konnectNamespacedRef:
name: cp-event-tls
network:
services:
kafka:
type: ClusterIP
ports:
- name: kafka
port: 9092
targetPort: 9092
' | kubectl apply -f -
Kubernetes Gateway 생성
포트 19092에서 TLS 트래픽을 수신하는 Gateway를 생성해요. 이 Gateway는 TLS 패스스루를 사용하기 때문에, Kong Event Gateway가 앞서 설정한 인증서로 여전히 TLS를 종료해요.
-
Gateway를 생성해요:echo ' apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: kong-keg namespace: kong spec: gatewayClassName: kong listeners: - name: kafka-tls protocol: TLS port: 19092 hostname: "*.keg.test.local" tls: mode: Passthrough certificateRefs: [] allowedRoutes: namespaces: from: Same kinds: - group: gateway.networking.k8s.io kind: TLSRoute ' | kubectl apply -f - -
Gateway가 수락될 때까지 기다려요:kubectl wait gateway/kong-keg -n kong --for=condition=Accepted=True --timeout=5m
Gateway에 TLSRoute 연결
TLSRoute는 와일드카드 Kafka 호스트명을 KegDataPlane이 노출하는 내부 Kafka Service에 바인딩해요.
TLSRoute를 생성해요:
echo '
apiVersion: gateway.networking.k8s.io/v1
kind: TLSRoute
metadata:
name: keg-tls
namespace: kong
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: kong-keg
namespace: kong
sectionName: kafka-tls
hostnames:
- "*.vc-tls-1.keg.test.local"
rules:
- backendRefs:
- group: ""
kind: Service
name: keg-tls-dp-kafka
port: 9092
' | kubectl apply -f -
검증
-
Gateway주소를 내보내요:export GATEWAY_IP=$(kubectl get gateway kong-keg -n kong -o jsonpath='{.status.addresses[0].value}') echo $GATEWAY_IP -
TLSRoute 조건을 확인해요:
kubectl get tlsroute keg-tls -n kong \ -o jsonpath='{range .status.parents[0].conditions[*]}{.type}={.status}{" "}{end}{"\n"}'
Kafka 메타데이터로 스모크 테스트하기
로컬 테스트를 위해 광고된 브로커 호스트명에 대한 호스트 별칭을 만들고 kcat으로 메타데이터를 요청해 보세요:
kubectl run kcat-tlsroute --rm -i --restart=Never --image=edenhill/kcat:1.7.1 -n kong \
--overrides='{"spec":{"hostAliases":[{"ip":"'"${GATEWAY_IP}"'","hostnames":["bootstrap.vc-tls-1.keg.test.local","broker-0.vc-tls-1.keg.test.local","broker-1.vc-tls-1.keg.test.local","broker-2.vc-tls-1.keg.test.local"]}]}}' \
--command -- kcat -b bootstrap.vc-tls-1.keg.test.local:19092 \
-X security.protocol=SSL \
-X enable.ssl.certificate.verification=false \
-L
가상 클러스터 dnsLabel을 기반으로 하는 DNS 이름으로 포트 19092에 광고되는 모든 브로커가 보이는 걸 확인할 수 있어요.
관련 리소스
다음 단계
더 알아보기 (Learn more)
- 이 페이지가 속한 이벤트 게이트웨이 배포 시리즈의 첫 걸음이에요 — Deploy Kong Event Gateway on Kubernetes
- 이 문서의 바로 전 단계인 포트 매핑 방식 배포 가이드예요 — Deploy Kong Event Gateway with port mapping
- SNI 라우팅 구성을 더 깊이 다루는 문서예요 — Configure SNI routing with Kong Event Gateway
- SNI로 라우팅되는 가상 클러스터 개념을 설명해요 — Virtual clusters
- Gateway와 TLSRoute 같은 Gateway API 리소스 활용법을 안내해요 — Gateway API
- 백엔드 클러스터, 리스너, 정책 등 이벤트 게이트웨이 리소스를 전반적으로 소개해요 — Learn more about Kong Event Gateway resources