Traefik with kubernetes Ingress Controller Hostregexp rule edition

301 Views Asked by At

I would like to apply HostRegExp with Traefik as ingress Controller. I have something similar like below with docker as provider in Traefik service. "traefik.http.routers.test.rule=HostRegexp(`{host:.+}`) && PathPrefix(`/test`)"

Would like to replicate similar stuff in Kubernetes.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-service
  annotations:
    #kubernetes.io/ingress.class: traefik
    # entryPoints Configuration
    traefik.ingress.kubernetes.io/router.entrypoints: web,websecure 
    traefik.ingress.kubernetes.io/router.tls: "true"
    #configuring rules
    #traefik.frontend.rule.type: HostRegexp
    
spec:
  rules:
    - host: `{host:.+}`
      http:
        paths:
          - path: /rmq
            pathType: Prefix
            backend:
              service:
                name: rabbitmq
                port:
                  name: http

Tried below options. Any inputs ?

1

There are 1 best solutions below

0
On

I don't know if this functionality is exposed through the Ingress provider, but you can do it using an IngressRoute resource. For example, if I have:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: example
spec:
  entryPoints:
    - web
  routes:
  - match: "HostRegexp(`{host:foo.*}.using.ingressroute`)"
    kind: Rule
    services:
    - name: example
      port: http

Then I can access the service using the hostnames like:

  • foo.using.ingressroute
  • foobar.using.ingressroute
  • foo.one.two.three.using.ingressroute