Path-based routing Ingress not working with rancher-ingress-controller

I am running a Kubernetes cluster (which has the default rancher-ingress-controller) and trying to use an Ingress with path-based routing, similar to the following example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: path-based-ingress
spec:
  rules:
  - http:
      paths:
      - path: /foo
        backend:
          serviceName: http-svc
          servicePort: 80

But when I make a request to the host ip address with a path (i.e. curl -i http://1.2.3.4/foo), I get a “404 - Not Found” response. If I change the path in the ingress config file to just “/” and run curl -i http://1.2.3.4/, everything works fine; I get a valid response.

Thanks in advance for any help!

FYI, I also tried using the native Load Balancer feature in Rancher; I selected “Add Load Balancer” to the ‘default’ stack. The result is the same. as described above. If I set a path to something like “/foo”, I get a 404 - Not Found response. If I set the path to “/”, it works properly.

As I understand it, Rancher uses HAProxy for its load balancing, so perhaps there is some general issue with HAProxy handling paths in the config?

I don’t think there is any issue, but a misunderstanding about how path routing works. The /foo is not stripped off of the request that is sent to the target container. So a request for /foo is going to your container and it responds 404 because it has no such path.

You can cause the prefix to be stripped off of the request using the custom config section. But this cannot really be on by default because it breaks any application that returns absolute or root-relative URLs in the response and expects them to be retrievable. This very commonly includes JS and CSS files referenced from returned HTML.

1 Like

Hi, This worked for me thank you.
Basically, I was hoping to set the path for ingress load balancing to something like /web => my-web-service/.
And I was getting the 404 not found. To make this work :

  • had to modify my web-app to handle the path /web and serve index.html on this path.
  • Make sure this is working locally
  • Create a new container for the latest code changes
  • And then the ingress rule started to work

My ingress LB rule : FYI

hostname to use :: my-pulblic-dns-address
path :: /web
target :: my-nodejs-service OR container
port :: 8080 (port which is exposed by coantiner)