Skip to content

Instantly share code, notes, and snippets.

@superseb
Last active October 31, 2023 10:46
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save superseb/ba6becd1a5e9c74ca17996aa59bcc67e to your computer and use it in GitHub Desktop.
Save superseb/ba6becd1a5e9c74ca17996aa59bcc67e to your computer and use it in GitHub Desktop.
Expose UDP service via NGINX ingress controller on Rancher 2 custom cluster

To expose UDP service via NGINX, you need four things:

  • Add port definition to DaemonSet (by default it only exposes TCP/80 and TCP/443)
  • Run your app
  • Create a service exposing your app
  • Add service definition to ConfigMap udp-services in the ingress-nginx namespace.

See https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md

Add port definition to DaemonSet

This kubectl patch command adds port UDP/3333 to the DaemonSet nginx-ingress-controller:

kubectl -n ingress-nginx patch ds/nginx-ingress-controller -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx-ingress-controller","ports":[{"containerPort":80,"hostPort":80,"name":"http","protocol":"TCP"},{"containerPort":443,"hostPort":443,"name":"https","protocol":"TCP"},{"containerPort":3333,"hostPort":3333,"name":"echotest","protocol":"UDP"}]}]}}}}'

Run your app

This will use the n0r1skcom/echo image which echo's everything on port 3333.

kubectl run --image=n0r1skcom/echo echo --port 3333

Create a service exposing your app

kubectl expose deploy/echo --port 3333 --protocol UDP

Add service definition to ConfigMap

kubectl -n ingress-nginx patch configmap udp-services -p '{"data":{"3333":"default/echo:3333"}}'

Test

nc -u NODE_IP 3333
test
Container information:
Hostname:       echo-5fc4bc4dc7-zm99z

Interface       NetMask         IP
lo              255.0.0.0       127.0.0.1
eth0            255.255.255.255 10.42.1.3

UDP Remote information:
IP:     10.42.0.0

Data received:
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment