UDP 트래픽 프록시하기
UDP 트래픽 프록시하기 (UDPRoute)
이 문서에서는 Kong Operator에서 UDPRoute를 사용해 UDP 트래픽을 프록시하는 방법을 안내해요. Gateway에 UDP 리스너를 추가하고 UDPRoute 리소스를 만들면, Kong Operator가 이를 Kong Gateway의 Service와 Route로 변환해 줘요. Kong Operator 설치와 라이선스 적용부터 Gateway 구성, UDP 백엔드 배포, 동작 검증까지 전 과정을 단계별로 따라 할 수 있어요.
출처: 문서
본문
TL;DR
Kong Operator로 UDP 트래픽을 라우팅하려면 어떻게 하나요?
Gateway에 UDP 리스너를 추가한 다음 UDPRoute 리소스를 생성하세요. Kong Operator는 UDPRoute를 Kong Gateway Service와 Route로 변환해요.
사전 준비
Kong Operator 실행 (Enterprise 라이선스 포함)
-
Kong Helm 차트를 추가하세요:
helm repo add kong https://charts.konghq.com helm repo update -
Helm을 사용해 Kong Operator를 설치하세요:
helm upgrade --install kong-operator kong/kong-operator -n kong-system \ --create-namespace \ --set image.tag=2.3 \admission 및 conversion 웹훅 인증서를 cert-manager가 발급하고 갱신하도록 하려면, 클러스터에 cert-manager를 설치하고 다음 단계에서 설치할 때 아래 인자를 전달해 cert-manager 연동을 활성화하세요:
--set global.webhooks.options.certManager.enabled=true이걸 활성화하지 않으면 차트가 자동으로 자체 서명 인증서를 생성해 주입해요. 이 인증서들의 라이프사이클 관리를 위해서는 cert-manager 활성화를 권장해요. Kong Operator는 컨트롤 플레인과 데이터 플레인 간 mTLS 통신을 위한 인증서에 서명할 인증 기관이 필요해요. 이건 Helm 차트가 자동으로 처리해요. 커스텀 CA 인증서를 제공해야 한다면, Helm 차트의
values.yaml에 있는certificateAuthority섹션을 참고해 자체 CA 인증서를 만들고 참조하는 방법을 알아보세요.
KongLicense를 적용하세요. 이때 라이선스가 ./license.json에 있다고 가정해요.
echo "
apiVersion: configuration.konghq.com/v1alpha1
kind: KongLicense
metadata:
name: kong-license
rawLicenseString: '$(cat ./license.json)'
" | kubectl apply -f -
UDPRoute는 포트별로 UDP 트래픽을 라우팅하기 위한 Kubernetes Gateway API 리소스예요. 이 가이드에서는 Kong Operator가 백엔드 Service로 UDP 트래픽을 프록시하도록 설정하는 방법을 보여줘요.
kong 네임스페이스 생성
데모가 실행될 kong 네임스페이스를 Kubernetes 클러스터에 생성하세요:
kubectl create namespace kong
{: data-test-step="block" }
Gateway 설정
HTTP 리스너가 있는 GatewayConfiguration, GatewayClass, Gateway를 생성하세요:
echo '
apiVersion: gateway-operator.konghq.com/v2beta1
kind: GatewayConfiguration
metadata:
name: kong-gateway-configuration
namespace: kong
spec:
dataPlaneOptions:
deployment:
podTemplateSpec:
spec:
containers:
- image: kong/kong-gateway:3.16
name: proxy
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: kong-udp
spec:
controllerName: konghq.com/gateway-operator
parametersRef:
group: gateway-operator.konghq.com
kind: GatewayConfiguration
name: kong-gateway-configuration
namespace: kong
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: kong-udp-gateway
namespace: kong
spec:
gatewayClassName: kong-udp
listeners:
- name: http
port: 80
protocol: HTTP' | kubectl apply -f -
UDP 백엔드 배포
UDP로 리스닝하는 소형 TFTP 테스트 서버인 tftp Service를 설치하세요:
kubectl apply -f https://developer.konghq.com/manifests/kic/udp-service.yaml -n kong
UDP 트래픽 라우팅
-
UDP리스너를 추가해서kong-udp-gatewayGateway를 다시 적용하세요:경고: 이 Gateway를 적용하면 리스너 목록이 교체돼요. 유지하려는 리스너는 모두 포함하세요.
echo 'apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: kong-udp-gateway namespace: kong spec: gatewayClassName: kong-udp listeners: - name: http port: 80 protocol: HTTP - name: stream9999 port: 9999 protocol: UDP allowedRoutes: namespaces: from: All' | kubectl apply -f - -
UDPRoute를 생성하세요:echo "apiVersion: gateway.networking.k8s.io/v1 kind: UDPRoute metadata: name: tftp namespace: kong spec: parentRefs: - name: kong-udp-gateway sectionName: stream9999 rules: - backendRefs: - name: tftp port: 9999 " | kubectl apply -f -
이 설정은 Kong Gateway가 포트 9999로 수신한 UDP 트래픽을 포트 9999의 tftp Service로 전달하도록 지시해요.
검증
-
Gateway가 프로그래밍될 때까지 기다리세요:
kubectl wait gateway/kong-udp-gateway -n kong \ --for=condition=Programmed=True \ --timeout=5m -
Gateway의 외부 IP를 확인하세요:
export PROXY_IP=$(kubectl get gateway kong-udp-gateway -n kong -o jsonpath='{.status.addresses[0].value}') echo $PROXY_IP -
프록시를 통해 TFTP 요청을 보내세요:
curl -s tftp://$PROXY_IP:9999/hello결과는 다음과 같이 나와야 해요:
Hostname: tftp-5849bfd46f-nqk9x Request Information: client_address=127.0.0.1 client_port=39364 real path=/hello request_scheme=tftp{:.no-copy-code}