0

In our Kubernetes Cluster we have a micro frontend, which is accessable under image-self-service:8080 without any additional path. To be able to use it in a bigger application I want to use an Nginx-Ingress to reroute from url-to-site/profile to image-self-service:8080/.

I have found and read this SO post, thats basically asking the same thing: Remove routing path from Kubernetes ingress and the linked documentation here: https://github.com/kubernetes/ingress-nginx/blob/main/docs/examples/rewrite/README.md

which resulted in me using a .yaml for my Ingress that looks like this: (sensitive Information removed)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
    traefik.ingress.kubernetes.io/router.entrypoints: websecure    
    traefik.ingress.kubernetes.io/router.tls: "true"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-origin: "*"
    nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS, DELETE"
    nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,X-LANG,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Api-Key,X-Device-Id,Access-Control-Allow-Origin"
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: intranet-backend-ingress
  namespace: intranet


spec:
  rules:
  - host: xxx-test.xxx.xxx
    http:
      paths:
      - backend:
          service:
            name: image-self-service
            port:
              number: 8080
        path: /profile(/|$)(.*)
        pathType: Prefix
      - backend:
          service:
            name: intranet-ui
            port:
              number: 8080
        path: /
        pathType: Prefix
    ...

For readability I also removed other endpoints which are more specific as I don't think those interfere. I have tried using nginx.ingress.kubernetes.io/rewrite-target: / and nginx.ingress.kubernetes.io/rewrite-target: /$2

If I remove the rewrite-target and add a specific path, the forwarding works but with the additional path, so it results in a 404 from the underlying webservice. The Response I get using the rewriting is simply: 404 page not found which I believe to be an Ingress message.

jujule
  • 11,125
  • 3
  • 42
  • 63
SirHawrk
  • 610
  • 1
  • 4
  • 17

0 Answers0