It is possible to expose ports other than 80 and 443 through the NGINX ingress in Kubernetes.
An example where this is needed is a DNS server which uses port 53 on both TCP and UDP. Pi-hole is a widely self-hosted DNS server that also works as an ad-blocker.
The way to expose those ports is, in a couple of points:
- Define the app that implements the service and exposes the ports to the cluster via a Kubernetes service;
- Configure the NGINX ingress controller to accept incoming requests from the ports, and forward them to the service.
There are a couple of caveats:
- NGINX supports UDP load balancing since version 1.9.13;
- Cannot route traffic based on host, only 1 service in the cluster can be exposed with this method;
- There is a bug on the
kubectl
client that prevents setting the same service ports on both protocols, if usingapply
, you can use the parameter--server-side=true
to mitigate the issue.
Source: https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/