To expose UDP service via NGINX, you need four things:
- Add port definition to DaemonSet (by default it only exposes
TCP/80
andTCP/443
) - Run your app
- Create a service exposing your app
- Add service definition to ConfigMap
udp-services
in theingress-nginx
namespace.
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"}]}]}}}}'
This will use the n0r1skcom/echo
image which echo's everything on port 3333.
kubectl run --image=n0r1skcom/echo echo --port 3333
kubectl expose deploy/echo --port 3333 --protocol UDP
kubectl -n ingress-nginx patch configmap udp-services -p '{"data":{"3333":"default/echo:3333"}}'
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