How to catch outgoing 404 with traefik

2/20/2019

I am using traefik as ingress for kubernetes. I need to do some special stuff if any of my services returns a 404 or there is no service to answer that request therefore again 404.

At the moment I have a default backend that is able to catch 404 when the ingress rules are not satisfied but when the service itself returns the 404 it renders its own page which is not what I want.

I tried achieving this with an annotation:

traefik.ingress.kubernetes.io/error-pages

but this is not ideal because I have to place this annotation on every single ingress rule in my cluster.

How can I catch ALL outgoing 404 from my cluster and send them to a special service of mine that does some magic with those 404s?

[EDIT]
For a little bit better understanding of what I am trying to do:

Using a default backend is somewhat fine because yes if it is not in the ingress rules then it works like a charm but if the request is as follows:

api.kube.mini/timeline/asd

and we have /timeline as ingress rule then the request will be passed to the service sitting on that rule but /asd in that service doesn't exist, therefore, the service returns it's own 404 page and I am unable to catch this request which I might need to redirect.

-- Ivailo Korakov
http-status-code-404
kubernetes
traefik
traefik-ingress

0 Answers