포트별 UDP 트래픽 프록시
포트별 UDP 트래픽 프록시 (Proxy UDP traffic by port)
Kong Ingress Controller에서 UDP 트래픽을 포트 단위로 프록시하는 방법을 단계별로 소개해요. UDPRoute 또는 UDPIngress 리소스를 만들면 Kong Gateway의 Service와 Route로 변환된다는 흐름을 먼저 짚어 줄게요. Konnect와 온프레미스 환경별 사전 준비부터 Gateway API와 Ingress 두 가지 방식의 라우팅 설정, 검증과 정리까지 함께 살펴봐요
출처: 문서
본문
TL;DR
Kong Ingress Controller로 UDP 트래픽을 라우팅하려면 어떻게 하나요?
UDPRoute 또는 UDPIngress 리소스를 만드세요. 그러면 이 리소스가 Kong Gateway Service와 Route로 변환돼요.
사전 준비
Konnect 배포: Kong Konnect
Konnect 계정이 없다면 온보딩 마법사를 통해 빠르게 시작할 수 있어요.
-
이 튜토리얼을 완료하려면 다음 Konnect 항목들이 필요해요:
- 개인 액세스 토큰(PAT): Konnect PAT 페이지를 열고 Generate Token을 선택해서 새 개인 액세스 토큰을 만드세요.
-
개인 액세스 토큰을 환경 변수로 설정하세요:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Gateway API 활성화
-
Kong Ingress Controller를 설치하기 전에 experimental Gateway API CRD를 설치하세요:
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.1/experimental-install.yaml{: data-test-prereq="block" }
-
사용할
Gateway와GatewayClass인스턴스를 만드세요.echo " apiVersion: v1 kind: Namespace metadata: name: kong --- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: name: kong annotations: konghq.com/gatewayclass-unmanaged: 'true' spec: controllerName: konghq.com/kic-gateway-controller --- apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: kong spec: gatewayClassName: kong listeners: - name: proxy port: 80 protocol: HTTP allowedRoutes: namespaces: from: All " | kubectl apply -n kong -f -{: data-test-prereq="block" }
Konnect 배포: KIC Control Plane 만들기
Konnect API를 사용해서 새로운 CLUSTER_TYPE_K8S_INGRESS_CONTROLLER Control Plane을 만드세요:
CONTROL_PLANE_DETAILS=$(curl -X POST "https://us.api.konghq.com/v2/control-planes" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"name": "My KIC CP",
"cluster_type": "CLUSTER_TYPE_K8S_INGRESS_CONTROLLER"
}'
)
나중에 values.yaml 파일을 작성할 때 id와 telemetry_endpoint가 필요해요. 환경 변수로 저장해 두세요:
CONTROL_PLANE_ID=$(echo $CONTROL_PLANE_DETAILS | jq -r .id)
CONTROL_PLANE_TELEMETRY=$(echo $CONTROL_PLANE_DETAILS | jq -r '.config.telemetry_endpoint | sub("https://";"")')
mTLS 인증서 만들기
Kong Ingress Controller는 TLS 인증서로 보안이 유지되는 연결을 통해 Konnect와 통신해요.
openssl을 사용해서 새 인증서를 생성하세요:
openssl req -new -x509 -nodes -newkey rsa:2048 -subj "/CN=kongdp/C=US" -keyout ./tls.key -out ./tls.crt
인증서를 curl로 Konnect API에 보내려면 한 줄짜리 문자열이어야 해요. awk를 사용해서 인증서 형식을 바꾸세요:
export CERT=$(awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' tls.crt);
다음으로, 인증서를 Konnect에 업로드하세요:
curl -X POST "https://us.api.konghq.com/v2/control-planes/$CONTROL_PLANE_ID/dp-client-certificates" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"cert": "'$CERT'"
}'
마지막으로, Kong Ingress Controller가 읽을 수 있도록 인증서를 Kubernetes 시크릿에 저장하세요:
kubectl create namespace kong -o yaml --dry-run=client | kubectl apply -f -
kubectl create secret tls konnect-client-tls -n kong --cert=./tls.crt --key=./tls.key
Konnect 배포: Kong Ingress Controller 실행(Konnect에 연결)
-
Kong Helm 차트를 추가하세요:
helm repo add kong https://charts.konghq.com helm repo update -
values.yaml파일을 만드세요:cat <<EOF > values.yaml controller: ingressController: image: tag: "3.5" env: feature_gates: "FillIDs=true" konnect: license: enabled: true enabled: true controlPlaneID: "$CONTROL_PLANE_ID" tlsClientCertSecretName: konnect-client-tls apiHostname: "us.kic.api.konghq.com" gateway: image: repository: kong tag: "3.9.3" env: konnect_mode: 'on' vitals: "off" cluster_mtls: pki cluster_telemetry_endpoint: "$CONTROL_PLANE_TELEMETRY:443" cluster_telemetry_server_name: "$CONTROL_PLANE_TELEMETRY" cluster_cert: /etc/secrets/konnect-client-tls/tls.crt cluster_cert_key: /etc/secrets/konnect-client-tls/tls.key lua_ssl_trusted_certificate: system proxy_access_log: "off" dns_stale_ttl: "3600" secretVolumes: - konnect-client-tls EOF{: data-test-prereq="block" }
-
Helm을 사용해서 Kong Ingress Controller를 설치하세요:
helm install kong kong/ingress -n kong --create-namespace --set controller.ingressController.env.feature_gates="GatewayAlpha=true" --values ./values.yaml --wait{: data-test-prereq="block" }
-
이후 명령에서 사용할 수 있도록
$PROXY_IP를 환경 변수로 설정하세요:export PROXY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}') echo $PROXY_IP
온프레미스 배포: Kong Ingress Controller 실행
-
Kong Helm 차트를 추가하세요:
helm repo add kong https://charts.konghq.com helm repo update -
Helm을 사용해서 Kong Ingress Controller를 설치하세요:
helm install kong kong/ingress -n kong --create-namespace --set controller.ingressController.env.feature_gates="GatewayAlpha=true" --wait{: data-test-prereq="block" }
-
이후 명령에서 사용할 수 있도록
$PROXY_IP를 환경 변수로 설정하세요:export PROXY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}') echo $PROXY_IP
필수 Kubernetes 리소스
이 how-to 가이드를 완료하려면 클러스터에서 몇 가지 Kubernetes 서비스를 사용할 수 있어야 해요. 이 서비스들은 이 how-to에서 만드는 리소스들이 사용해요.
kubectl apply -f https://developer.konghq.com/manifests/kic/udp-service.yaml -n kong
{: data-test-prereq="block" }
서비스들의 파드가 준비될 때까지 기다리세요:
kubectl wait --for=condition=Ready pod --all -n kong --timeout=300s
{: data-test-prereq="block" }
UDP 리스닝 추가
Kong Gateway는 기본적으로 어떤 UDP 리스닝 설정도 포함하지 않아요. UDP 리스닝을 노출하려면 Deployment의 환경 변수와 포트 설정을 업데이트하세요.
-
Deployment에서
KONG_STREAM_LISTEN환경 변수를 설정하고 포트9999를 노출하세요:kubectl patch deploy -n kong kong-gateway --patch '{ "spec": { "template": { "spec": { "containers": [ { "name": "proxy", "env": [ { "name": "KONG_STREAM_LISTEN", "value": "0.0.0.0:9999 udp" } ], "ports": [ { "containerPort": 9999, "name": "stream9999", "protocol": "UDP" } ] } ] } } } }' -
새 포트를 반영하도록 프록시 Service를 업데이트하세요:
kubectl patch service -n kong kong-gateway-proxy --patch '{ "spec": { "ports": [ { "name": "stream9999", "port": 9999, "protocol": "UDP", "targetPort": 9999 } ] } }'
UDP 트래픽 라우팅
서비스를 외부에 노출하려면 Gateway API에서는 UDPRoute 리소스를, Ingress에서는 UDPIngress 리소스를 만드세요.
Gateway API
UDPRoute가 조정되도록 Gateway 리소스에 UDP 리스너를 추가로 설정하세요:
kubectl patch -n kong --type=json gateway kong -p='[
{
"op":"add",
"path":"/spec/listeners/-",
"value":{
"name":"stream9999",
"port":9999,
"protocol":"UDP",
"allowedRoutes": {
"namespaces": {
"from": "All"
}
}
}
}
]'
다음으로, UDPRoute를 만드세요:
echo "apiVersion: gateway.networking.k8s.io/v1alpha2
kind: UDPRoute
metadata:
name: tftp
namespace: kong
spec:
parentRefs:
- name: kong
namespace: kong
rules:
- backendRefs:
- name: tftp
port: 9999
" | kubectl apply -f -
Ingress
중요: UDPIngress 지원 중단 안내
UDPIngress커스텀 리소스는 Kong Ingress Controller 3.5부터 **지원이 중단(deprecated)**됐고, Kong Operator 2.0.0에서 완전히 제거될 예정이에요. 이 리소스는 기존 Kubernetes Ingress API의 한계를 해결하기 위해 만들어졌지만, Gateway API가 성숙해지고 널리 채택되면서 이제는 중복이 됐어요.Kong Operator 2.0.0으로 업그레이드하기 전에는 마이그레이션이 필요해요. Ingress에서 Gateway API로 마이그레이션 가이드를 사용해서 기존
UDPIngress리소스를 Gateway API 대응 항목(UDPIngress→Gateway+UDPRoute)으로 마이그레이션하세요.
echo "apiVersion: configuration.konghq.com/v1beta1
kind: UDPIngress
metadata:
name: tftp
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
spec:
rules:
- backend:
serviceName: tftp
servicePort: 9999
port: 9999
" | kubectl apply -f -
이 설정은 Kong Gateway 프록시의 UDP 포트 9999로 들어온 트래픽을 TFTP 테스트 서버의 포트 9999로 라우팅해요.
설정 검증
프록시를 통해 TFTP 요청을 보내세요:
curl -s tftp://$PROXY_IP:9999/hello
결과는 다음과 같이 나와야 해요:
Hostname: tftp-5849bfd46f-nqk9x
Request Information:
client_address=10.244.0.1
client_port=39364
real path=/hello
request_scheme=tftp
정리
생성한 Kubernetes 리소스 삭제
kubectl delete -n kong -f https://developer.konghq.com/manifests/kic/udp-service.yaml
클러스터에서 KIC 제거
helm uninstall kong -n kong
관련 리소스
더 알아보기 (Learn more)
- UDPRoute나 UDPIngress가 변환되는 대상인 Kong Gateway의 Service 엔티티를 설명해요 — Kong Gateway Service
- UDP 트래픽 라우팅의 핵심인 Route 엔티티의 개념을 확인할 수 있어요 — Route
- Ingress 방식에서 Gateway API 방식으로 전환하는 방법을 다뤄요 — Migrating from Ingress to Gateway API
- Kong Ingress Controller의 전체 문서를 한 곳에서 볼 수 있어요 — All KIC documentation
- Konnect 계정이 없을 때 온보딩 마법사로 빠르게 시작하는 방법을 안내해요 — onboarding wizard