Disable path rewrite for Kubernetes fan out Ingress

10/7/2019

My Kubernetes application uses an Ingress to proxy requests to different servers, according to the URL given: I want a fanout configuration. I want the URLs of the requests not to be rewritten when forwarded to the servers. How do I do that?

I want all the /api URLs forwarded to the be service, and all others forwarded to the fe service. But I want the URLs forwarded unchanged. For example

  • a request for /api/users should be forwarded to the be service as a request for /api/users.
  • a request for /foo should be forwarded to the fe service as a request for /foo.

My current Ingress resource is like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  ...
spec:
  ...
  rules:
    - host: ...
    - http:
        paths:
          - path: /api
            backend:
              serviceName: be
              servicePort: 8080
          - path: /
            backend:
              serviceName: fe
              servicePort: 80

but that does not work; it gives 404 Not Found for requests.

-- Raedwald
kubernetes
kubernetes-ingress
url-rewriting

1 Answer

10/7/2019

The Kubernetes ingress isn't rewriting your request URLs, the ingress controller is doing this (whatever you happen to be using). For instance, if your ingress controller is Nginx, you can control this behavior with annotations on the ingress.

-- Grant David Bachman
Source: StackOverflow