How to handle sub-route and a root route in the same ingress

Viewed 167

I have one ingress handling traffic for 2 different services:

rules:
    - http:
        paths:
          - path: /stats
            backend:
              serviceName: info-dashboard
              servicePort: 80
          - path: /*
            backend:
              serviceName: portal
              servicePort: 80

I also have URL rewrite rules for the info-dashboard. Rewrite /stats -> / when the traffic is sent to the service. Because the app behind the backend service expects its endpoint hits to start with /, not /stats.

So, the issue is that hitting /stats on the LB is fine, but subsequent calls fail (eg. automated app calls to fetch javascript and other logic). They fail because they try to load from /, which is a different app.

The app is a Next.js app. So, I also tried setting up a basePath. But the issue persists.

Actually, if I remove the /stats -> / redirect rule from the LB, any hits to /stats just direct me to the other app on the ingress - the portal. I'm confused why and how this works.

Am I missing something in the setup?

1 Answers

From the k8s-ingress point of view everything is fine. It looks like the problem lays in your info-dashboard application, which doesn't "know" that it's running behind a proxy. To fix this your application should be configured using some kind of a basePath/rootPath flag (depending on your application) pointing to /stats so it can hit /stats as configured.

Related