JS files not laoding for Application when using Kubernetes nginx Ingress rules

5/22/2020

I am trying to add path based ingress rules for react web application. If I go to example.com/abc to abc application and example.com/xyz to Xyz application

kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - path: /abc(/|$)(.*)
        backend:
          serviceName: abc-service
          servicePort: 80
      - path: /xyz(/|$)(.*)
        backend:
          serviceName: xyz-service
          servicePort: 80

But if I tried path / instead of /abc it works. Not for xyz

kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - path: /(.*)
        backend:
          serviceName: abc-service
          servicePort: 80
      - path: /xyz(/|$)(.*)
        backend:
          serviceName: xyz-service
          servicePort: 80
-- avadhut007
kubernetes-ingress
nginx-ingress
reactjs

1 Answer

5/22/2020

Try this:

kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths:
      - path: /abc/?(.*)
        backend:
          serviceName: abc-service
          servicePort: 80
      - path: /xyz/?(.*)
        backend:
          serviceName: xyz-service
          servicePort: 80
-- zirmax
Source: StackOverflow