Access different react paths with root in ingress

Viewed 881

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

This this maybe you want - Nginx rewrite

nginx.ingress.kubernetes.io/rewrite-target

This is the full doc. rewrite

Related