Traefik routes to another service instead of returning 503 when /api backend is down

Hi everyone,

I have configured multiple Traefik Ingress resources for the same host: one handling the / path prefix and another handling /api. Each Ingress points to a different service:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: a
spec:
ingressClassName: traefik
rules:

  • host: "example.com"
    http:
    paths:
  • path: /api
    pathType: Prefix
    backend:
    service:
    name: a
    port:
    number: 9090

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: b
spec:
ingressClassName: traefik
rules:

  • host: "example.com"
    http:
    paths:
  • path: /
    pathType: Prefix
    backend:
    service:
    name: b
    port:
    number: 8080

When the pod behind service a is running properly, requests to /api are handled as expected. However, when that pod becomes unavailable or unhealthy, requests to /api/... are routed to service b (the / path) instead of returning an error.

As far as I understand, this might be default behavior, but I would prefer Traefik to return a 503 Service Unavailable response (or a similar error) when the /api backend is not available, rather than falling back to another service.

Is there a way to configure Traefik to achieve this behavior?

For the Docker provider there is allowEmptyServices, maybe there is something similar for k8s.

Hi,

you could try merging the two ingresses into one (though, I'm not 100% if it'll fix it, but I don't see a reason to have two different ingress objects for that use case). I'm a bit low on time and unable to setup such a scenario to test it.
The same question was asked a couple of days ago here (there, you'll also find the two merged ingress objects):