본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

포트 매핑으로 Kong Event Gateway 배포

원문 보기 위키 갱신

포트 매핑으로 Kong Event Gateway 배포 (Deploy Kong Event Gateway with port mapping)

이 문서는 Kong Operator를 사용해 Kong Event Gateway를 포트 매핑 방식으로 배포하는 과정을 단계별로 안내해요. KonnectEventGateway, 백엔드 클러스터, 가상 클러스터, 리스너, KegDataPlane, 리스너 정책, consume·produce 정책을 차례로 만들면서 전체 배포 흐름을 따라가 봐요. 포트 매핑은 Kafka 클라이언트가 부트스트랩 포트 하나와 브로커별 포트를 통해 연결되는 가장 간단한 배포 패턴이라 검증용으로 적합해요. 마지막에는 Kafka 메타데이터로 스모크 테스트를 진행하고, 프로덕션 환경에서는 SNI 라우팅 방식을 권장한다는 점까지 짚고 넘어갈게요

출처: 문서

본문

TL;DR

Kong Operator로 Kong Event Gateway는 어떻게 배포해요? KonnectEventGateway, 백엔드 클러스터, 가상 클러스터, 리스너, KegDataPlane, 리스너 정책, 그리고 컨슘 정책과 프로듀스 정책을 만들어요.

사전 준비

시리즈 사전 준비

이 페이지는 Kubernetes에 Kong Event Gateway 배포하기 시리즈의 일부예요.

이 페이지를 진행하기 전에 이전 페이지인 Kong Event Gateway용 Kong Operator 설치를 먼저 완료하세요.

Kong Konnect

Konnect 계정이 없다면 온보딩 마법사로 빠르게 시작할 수 있어요.

  1. 이 튜토리얼을 완료하려면 다음의 Konnect 항목들이 필요해요:

    • 개인 액세스 토큰(PAT): Konnect PAT 페이지를 열고 Generate Token을 선택해서 새 개인 액세스 토큰을 만드세요.
  2. 개인 액세스 토큰을 환경 변수로 설정해요:

    export KONNECT_TOKEN='YOUR KONNECT TOKEN'
    

KonnectAPIAuthConfiguration 리소스 만들기

kubectl create namespace kong --dry-run=client -o yaml | kubectl apply -f -
echo '
kind: KonnectAPIAuthConfiguration
apiVersion: konnect.konghq.com/v1alpha1
metadata:
  name: konnect-api-auth
  namespace: kong
spec:
  type: token
  token: "'$KONNECT_TOKEN'"
  serverURL: us.api.konghq.com
' | kubectl apply -f -

이 배포 패턴은 Kong Event Gateway를 검증하는 가장 간단한 방법이에요.

이 패턴은 LoadBalancer 서비스를 노출하고 portMapping을 사용해서 Kafka 클라이언트가 부트스트랩 포트 하나와 브로커별 포트 하나를 통해 연결하게 해요. 프로덕션 환경에서는 Kong Operator와 함께 Kong Gateway를 사용해 TLSRoute와 SNI 와일드카드를 설정하는 방식을 추천해요.

KonnectEventGateway 만들기

KonnectEventGateway 리소스는 Konnect에 Event Gateway 컨트롤 플레인을 만들고, 이 가이드의 나머지 리소스가 연결될 부모를 제공해요.

  1. KonnectEventGateway 리소스를 만들어요:

    echo '
    apiVersion: konnect.konghq.com/v1alpha1
    kind: KonnectEventGateway
    metadata:
      name: cp-event-1
      namespace: kong
    spec:
      apiSpec:
        name: cp-event-1
        description: Event Gateway control plane managed by Kubernetes
      konnect:
        authRef:
          name: konnect-api-auth
    ' | kubectl apply -f -
    
  2. 리소스가 준비될 때까지 기다려요:

    kubectl wait konnecteventgateway/cp-event-1 -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    

백엔드 클러스터 만들기

EventGatewayBackendCluster 리소스는 Kong Event Gateway에 어떤 업스트림 Kafka 클러스터에 연결할지 알려줘요. 이 예제에서는 kafka 네임스페이스의 Bitnami Kafka 부트스트랩 서비스를 가리켜요. 자세한 내용은 백엔드 클러스터 문서를 확인하세요.

  1. EventGatewayBackendCluster 리소스를 만들어요:

    echo '
    apiVersion: configuration.konghq.com/v1alpha1
    kind: EventGatewayBackendCluster
    metadata:
      name: default-backend-cluster
      namespace: kong
    spec:
      gatewayRef:
        type: namespacedRef
        namespacedRef:
          name: cp-event-1
      apiSpec:
        name: default_backend_cluster
        bootstrapServers:
          - kafka-cluster.kafka.svc.cluster.local:9092
        authentication:
          type: anonymous
          anonymous: {}
        insecureAllowAnonymousVirtualClusterAuth: Enabled
        tls:
          enabled: Disabled
    ' | kubectl apply -f -
    
  2. 리소스가 준비될 때까지 기다려요:

    kubectl wait eventgatewaybackendcluster/default-backend-cluster -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    

가상 클러스터와 리스너 만들기

EventGatewayVirtualCluster 리소스는 클라이언트가 연결하는 Kafka 쪽 클러스터이고, EventGatewayListener 리소스는 그 클라이언트 연결을 받아들이는 네트워크 포트를 열어줘요. 자세한 내용은 가상 클러스터 문서와 리스너 문서를 확인하세요.

  1. EventGatewayVirtualCluster와 EventGatewayListener 리소스를 만들어요:

    echo '
    apiVersion: configuration.konghq.com/v1alpha1
    kind: EventGatewayVirtualCluster
    metadata:
      name: example-virtual-cluster
      namespace: kong
    spec:
      eventGatewayBackendClusterRef:
        type: namespacedRef
        namespacedRef:
          name: default-backend-cluster
      apiSpec:
        name: example_virtual_cluster
        dnsLabel: vcluster-1
        aclMode: passthrough
        authentication:
          - type: anonymous
        namespace:
          prefix: "vc1_"
          mode: hide_prefix
    ---
    apiVersion: configuration.konghq.com/v1alpha1
    kind: EventGatewayListener
    metadata:
      name: example-listener
      namespace: kong
    spec:
      apiSpec:
        name: example_listener
        addresses:
          - 0.0.0.0
        ports:
          - "9092-9095"
      gatewayRef:
        type: namespacedRef
        namespacedRef:
          name: cp-event-1
    ' | kubectl apply -f -
    
  2. 리소스들이 준비될 때까지 기다려요:

    kubectl wait eventgatewayvirtualcluster/example-virtual-cluster -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    
    kubectl wait eventgatewaylistener/example-listener -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    

KegDataPlane 배포하기

KegDataPlane 리소스는 Kubernetes 내에서 Kong Event Gateway를 실행해요. 포트 매핑 패턴에서는 부트스트랩 포트 하나와 브로커별 포트 하나를 갖는 LoadBalancer 서비스를 노출해요.

KegDataPlane을 배포해요:

echo '
apiVersion: eventgateway.konghq.com/v1alpha1
kind: KegDataPlane
metadata:
  name: my-event-gateway-dp
  namespace: kong
spec:
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp-event-1
  network:
    services:
      kafka:
        type: LoadBalancer
        ports:
          - name: kafka
            port: 9092
            targetPort: 9092
          - name: broker-1
            port: 9093
            targetPort: 9093
          - name: broker-2
            port: 9094
            targetPort: 9094
          - name: broker-3
            port: 9095
            targetPort: 9095
' | kubectl apply -f -

LoadBalancer 주소 내보내기

리스너 정책에는 명시적인 advertisedHost가 필요해요. Kafka 서비스에서 LoadBalancer IP를 내보내요:

export KAFKA_LB_HOST=$(kubectl get service my-event-gateway-dp-kafka -n kong \
  -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo $KAFKA_LB_HOST

리스너 정책 만들기

EventGatewayListenerPolicy는 리스너를 가상 클러스터에 연결해요. 이 모드에서 portMapping은 외부 부트스트랩 포트 하나와 브로커별 외부 포트 하나를 매핑해요. 자세한 내용은 Event Gateway 정책 문서를 확인하세요.

  1. EventGatewayListenerPolicy 리소스를 만들어요:

    echo '
    apiVersion: configuration.konghq.com/v1alpha1
    kind: EventGatewayListenerPolicy
    metadata:
      name: example-listener-policy
      namespace: kong
    spec:
      apiSpec:
        type: forwardToVirtualCluster
        forwardToVirtualCluster:
          name: forward
          config:
            type: portMapping
            portMapping:
              advertisedHost: '"$KAFKA_LB_HOST"'
              bootstrapPort: at_start
              destination:
                name: example_virtual_cluster
      eventGatewayListenerRef:
        type: namespacedRef
        namespacedRef:
          name: example-listener
    ' | kubectl apply -f -
    
  2. 리소스가 준비될 때까지 기다려요:

    kubectl wait eventgatewaylistenerpolicy/example-listener-policy -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    

컨슘 정책과 프로듀스 정책 만들기

이 선택적인 가상 클러스터 정책들을 사용하면 컨슘 트래픽과 프로듀스 트래픽을 독립적으로 제어할 수 있어요. 이 예제에서는 각 경로에 헤더를 추가해서 정책이 잘 붙었는지 확인할 수 있어요. 자세한 내용은 Event Gateway 정책 문서를 확인하세요.

  1. EventGatewayVirtualClusterConsumePolicy와 EventGatewayVirtualClusterProducePolicy 리소스를 만들어요:

    echo '
    apiVersion: configuration.konghq.com/v1alpha1
    kind: EventGatewayVirtualClusterConsumePolicy
    metadata:
      name: example-virtual-cluster-consume-policy
      namespace: kong
    spec:
      eventGatewayVirtualClusterRef:
        type: namespacedRef
        namespacedRef:
          name: example-virtual-cluster
      apiSpec:
        type: modifyHeaders
        modifyHeaders:
          name: example_consume_policy
          description: Add a marker header to consumed records
          config:
            actions:
              - op: set
                set:
                  key: x-kong-consume-policy
                  value: example
    ---
    apiVersion: configuration.konghq.com/v1alpha1
    kind: EventGatewayVirtualClusterProducePolicy
    metadata:
      name: example-virtual-cluster-produce-policy
      namespace: kong
    spec:
      eventGatewayVirtualClusterRef:
        type: namespacedRef
        namespacedRef:
          name: example-virtual-cluster
      apiSpec:
        type: modifyHeaders
        modifyHeaders:
          name: example_produce_policy
          description: Add a marker header to produced records
          config:
            actions:
              - op: set
                set:
                  key: x-kong-produce-policy
                  value: example
    ' | kubectl apply -f -
    
  2. 리소스들이 준비될 때까지 기다려요:

    kubectl wait eventgatewayvirtualclusterconsumepolicy/example-virtual-cluster-consume-policy -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    
    kubectl wait eventgatewayvirtualclusterproducepolicy/example-virtual-cluster-produce-policy -n kong \
      --for=condition=Programmed=True \
      --timeout=10m
    

Kafka 메타데이터로 스모크 테스트하기

클러스터에서 kcat을 실행하고 브로커 메타데이터를 요청해요:

kubectl run kcat-portmap --rm -i --restart=Never --image=edenhill/kcat:1.7.1 -n kong \
  --command -- kcat -b ${KAFKA_LB_HOST}:9092 -L

포트 9092의 부트스트랩 엔드포인트 하나와 브로커별로 9093, 9094, 9095 포트가 각각 보여야 해요. 예를 들면 다음과 같아요:

Metadata for all topics (from broker -1: 127.0.0.0:9092/bootstrap):
 3 brokers:
  broker 0 at 127.0.0.0:9093
  broker 1 at 127.0.0.0:9094
  broker 2 at 127.0.0.0:9095 (controller)
 0 topics:
pod "kcat-portmap" deleted from kong namespace

{:.no-copy-code}

관련 리소스

다음 단계

더 알아보기 (Learn more)