Traefik on Kubernetes does not keep path over redirect

9/28/2018

I have a Traefik on Kubernetes that acts as ingress and load balancer. I have a ingress setup like this:

{
    "apiVersion": "extensions/v1beta1",
    "kind": "Ingress",
    "metadata": {
        "name": "nppl-ingress",
        "annotations": {
            "kubernetes.io/ingress.class": "traefik",
            "traefik.frontend.rule.type": "PathPrefixStrip"
        }
    },
    "spec": {
        "rules": [
            {
                "host": "" ,
                "http": {
                    "paths": [
                        {
                            "path": "/discover-service",
                            "backend": {
                                "serviceName": "discover-service",
                                "servicePort": "discover-port"
                            }
                        },
                        {
                            "path": "/config-server",
                            "backend": {
                                "serviceName": "config-server",
                                "servicePort": "config-port"
                            }
                        }

                    ]
                }
            }
        ]
    }
}

When, for example, I hit "http://IP/config-server", because I have a basic auth on that service, the service does a redirect over "http://IP/login" so I get a 404 but I was expecting "http://IP/config-server/login". What is wrong with my configuration? I also tried "PathPrefix" and "Path" under rule type but it doesn't work. I need to keep my base path when my services perform redirects.

-- Justin
kubernetes
traefik
traefik-ingress

1 Answer

9/28/2018

The issue here is that PathPrefixStrip removes /config-server and it initially forwards the request to your backend with just /. However, when your backend redirects it's a new request and the Ingress doesn't understand the request to / or /login. You could create two Ingress(es) for each backend and use single backend in each with a path to /. But this would mean adding a new ingress-class and the good news is that Traefik supports it. You could also try an nginx ingress which has the --ingress-class option.

You can find more information on how to create multiple ingress controllers here

If you want a single Ingress it will also be tricky since you might have to add logic in your app to understand the /config-server path for example.

-- Rico
Source: StackOverflow