'How to configure Traefik UDP Ingress?

My UDP setup doesn't work.

In traefik pod,

--entryPoints.udp.address=:4001/udp

is added. The port is listening and on traefik UI, it shows udp entrypoints port 4001. So entry-point UDP 4001 is working.

I have applied this CRD:

kind: IngressRouteUDP
metadata:
  name: udp
spec:
  entryPoints:
    - udp
  routes:
  - services:
    - name: udp
      port: 4001

kubrnetes service CRD:

apiVersion: v1
kind: Service
metadata:
  name: udp
spec:
  selector:
    app: udp-server
  ports:
    - protocol: UDP
      port: 4001
      targetPort: 4001

got error on traefik UI:

NAME: default-udp-0@kubernetescrd
ENTRYPOINTS: udp
SERVICE:
ERRORS: the udp service "default-udp-0@kubernetescrd" does not exist

What did I wrong? Or is it a bug? traefik version 2.3.1



Solution 1:[1]

So I ran into the trouble using k3s/rancher and traefik 2.x. The problem here was that configuring the command line switch only showed up a working environment in the traefik dashboard, - but it just did not worked.

In k3s the solution is to provide a traefik-config.yam besite the trafik.yaml. traefik.yaml is always recreated on a restart of k3s.

Put traefik-config.yaml to /var/lib/rancher/k3s/server/manifests/traefik-config.yaml is keeping changes persistent.

What misses is the entrypoint declaration. You may assume this is done as well by the command line switch, but it is not.

apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
  name: traefik
namespace: kube-system
spec:
  valuesContent: |-
    additionalArguments:
    - "--entryPoints.udp.address=:55000/udp"
  entryPoints:
    upd:
      address: ':55000/upd'

Before going further check the helm install job in the name kube-system. If one of the two helm install jobs error out, traefik won't work.

In case everything worked as above and you still have trouble. Then one option is just to configure the upd traffic as a normal kubernetes loadbalancer service. Like this example, that was successfully tested by me

  apiVersion: v1
  kind: Service
  metadata:
    name: nginx-udp-ingress-demo-svc-udp
  spec:
    selector:
      app: nginx-udp-ingress-demo
    ports:
      - protocol: UDP
        port: 55000
        targetPort: 55000
    type: LoadBalancer

The entry type: LoadBalancer will start a pod on ony kubernets node, that will send incoming UDP/55000 to the load balancer service.

This worked for me on a k3s cluster. But is not a native traefik solution asked in the question. More a work around, that make things work in the first place.

  1. I found a source that seem to handle the Traefik solution on https://github.com/traefik/traefik/blob/master/docs/content/routing/providers/kubernetes-crd.md.

That seems to have a working solution. But it has very slim expanation and shows just the manifests. I need to test this out, and come back.

This worked on my system.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1