'How to create a tcp service in traefik 2.2.1

I am trying to create a tcp service like this in kubernetes cluster followed by official docs:

apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
  name: app-mysql
spec:
    tcp:
      services:
        my-service:
           loadBalancer:
             servers:
               - address: '<private-ip-server-1>:<private-port-server-1>'
               - address: '<private-ip-server-2>:<private-port-server-2>'

and I only see the traefik service in lens, in the traefik dashboard found nothing:

image

What should I do to create a TCP Service in traefik 2.2.1?



Solution 1:[1]

Assuming you'd like to talk to TCP services running in Kubernetes. For TCP you don't need really need a TraefikService, you can just use an IngressRouteTCP resource.

You can see in the docs that the IngressRouteTCP can talk directly to a K8s service.

image1

Similarly to the example you can have something like this:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteUDP
metadata:
  name: my-ingress-udp-route
  namespace: default
spec:
  entryPoints:
    - myentrypoint
  routes:
    - match: HostSNI(`mysql.example.com`)
      services:
        - name: app-mysql ? K8s Service
          port: 3306

Notes:

  • TraefikService can be used for in regular IngressRoute resources, and not supported in TCP/UDP case today)

  • Not sure how you plan to load balance a MySQL service though, as this typically happens at the application level or you need a particular proxy that handles your reads/writes and data consistency)

??

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 Rico