Proxy UDP traffic by port
Create a UDPRoute
or UDPIngress
resource, which will then be converted in to a Kong Gateway Service and Route.
Prerequisites
Kong Konnect
If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.
- The following Konnect items are required to complete this tutorial:
- Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Set the personal access token as an environment variable:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Copied to clipboard!
Add UDP listens
Kong Gateway doesn’t include any UDP listen configuration by default. To expose UDP listens, update the Deployment’s environment variables and port configuration.
-
Set the
KONG_STREAM_LISTEN
environment variable and expose port9999
in the Deployment: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" } ] } ] } } } }'
Copied to clipboard! -
Update the proxy Service to indicate the new ports:
kubectl patch service -n kong kong-gateway-proxy --patch '{ "spec": { "ports": [ { "name": "stream9999", "port": 9999, "protocol": "UDP", "targetPort": 9999 } ] } }'
Copied to clipboard!
Route UDP traffic
To expose the service to the outside world, create a UDPRoute resource for Gateway APIs or a UDPIngress resource for Ingress.
This configuration routes traffic to UDP port 9999
on the
Kong Gateway proxy to port 9999
on the TFTP test server.
Validate your configuration
Send a TFTP request through the proxy:
curl -s tftp://$PROXY_IP:9999/hello
The results should look like this:
Hostname: tftp-5849bfd46f-nqk9x
Request Information:
client_address=10.244.0.1
client_port=39364
real path=/hello
request_scheme=tftp
Cleanup
Delete created Kubernetes resources
kubectl delete -n kong -f https://developer.konghq.com/manifests/kic/udp-service.yaml