Proxy UDP traffic by port

Related Documentation
Tags
Related Resources
TL;DR

Create a UDPRoute or UDPIngress resource, which will then be converted in to a Kong Gateway Service and Route.

Prerequisites

If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.

  1. 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.
  2. 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.

  1. Set the KONG_STREAM_LISTEN environment variable and expose port 9999 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!
  2. 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
Copied to clipboard!

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
Copied to clipboard!

Cleanup

kubectl delete -n kong -f https://developer.konghq.com/manifests/kic/udp-service.yaml
Copied to clipboard!

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!