skip to Main Content

I have two react apps, one is for administrators and the other is for normal users. Both have root / access. To enable the admin to access their page while normal user their respective pages, I added a redirect route in react router of admin, it redirects from admin to /.
I then added the two backends in my ingress a follows:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    # nginx.ingress.kubernetes.io/use-regex: "true"
    # nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
     paths:
      - path: /
        pathType: Prefix
          backend:
            serviceName: user-service
            servicePort: 3000

      - path: /admin
        pathType: Exact
          backend:
            serviceName: admin-service
            servicePort: 4000

The thing is this, it does not load the admin page. I don’t know why… Is there a way to load this different apps with same root paths? (both root paths is /)

2

Answers


  1. In your admin service please make sure that you are serving from the relative path (here /admin).

    In CRA you can do it by configuring the homepage in package.json

     "homepage": "http://example.com/admin",
    

    Refer: https://create-react-app.dev/docs/deployment/#building-for-relative-paths

    Login or Signup to reply.
  2. This this maybe you want – Nginx rewrite

    nginx.ingress.kubernetes.io/rewrite-target

    This is the full doc.
    rewrite

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search