[SOLVED] Problem to migrate ingress to ingresRoute -kubernetes

Hi
I migrate most of my services to work with traefik v2 but I have an ingress manifest that still didn't work as expected:

This ingress can access 2 services according to a path


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik
generation: 1
labels:
app: my-app
name: my-ingress
namespace: my-ns
spec:
rules:

  • host: my-app.domain.com
    http:
    paths:
    • backend:
      serviceName: service1
      servicePort: 10444
      path: /
    • backend:
      serviceName: service2
      servicePort: 8046
      path: /api/somepath/path//
      status:
      loadBalancer: {}

How I should migrate it as an ingressRoute record?
thx

Hi @demig

You can use the combination of Path and PathPrefix to create the rule. Here is the link to documentation:

https://doc.traefik.io/traefik/routing/routers/#rule

Please note the difference between Path and PathPrefix - it is well explained in the docs.

Here is the example config:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: whoami-crd-https
spec:
  entryPoints:
    - websecure
  routes:
    - kind: Rule
      match: Host(`whoami.127.0.0.1.nip.io`)
      services:
        - kind: Service
          name: whoami-svc
          port: 80
    - kind: Rule
      match: Host(`whoami.127.0.0.1.nip.io`) && Path(`/exact-match`)
      services:
        - kind: Service
          name: whoami-2-svc
          port: 80
 
  tls:
    certResolver: le
    options:
      name: tlsoptions

Thx , actually I tried all the time with Path and after changing to PathPrefix it started to work !
Thx.