How to expose an Angular Webapp via Ingress on a baremetal Kubernetes Cluster

Viewed 47

Using Metallb and nginx (both latest version), it is already possible to access some apps such as Elasticsearch and Kibana via Ingress. My Ingress for an Angular application with a .NET backend, looks like this:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: "true"
    # nginx.ingress.kubernetes.io/configuration-snippet: |
    #   rewrite ^/myapp/(.*)$ /$1 break; # <- didn't work
  name: myapp-ingress
spec:
  rules:
  - host: "kubernetes.my.domain"
    http:
      paths:
      - path: /myapp(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: myapp-svc
            port:
              number: 80

I'm mainly a backend developer so maybe it's something simple, but I'm having a really hard time figuring out why this doesn't work. I tried various different ways to rewrite the request but none worked. The ingress, service, and deployment are all in the same namespace, the service works flawlessly if I expose it via NodePort, the webapp is accessible and works correctly.

However, as soon as I change the service to ClusterIP and apply the ingress, the routing seems to work, but the page remains empty. Checking the console I can see the various requests such as GET https://kubernetes.my.domain/runtime.d0489476102a2801.js net::ERR_ABORTED 404 and GET https://kubernetes.my.domain/favicon.ico 404 which leads me to believe that it is trying to fetch them from root of the domain instead of root from the app (which the regex should do if my understanding of it is correct). I also tried changing the base href in Angular to "/myapp" but that didn't work either. The error simply changes to GET https://kubernetes.my.domain/myapp/runtime.d0489476102a2801.js net::ERR_ABORTED 404

Due to trying the various ingress variations and href solutions found here and on other sites with no success, I'm kind of at a loss. Therefore I think there is something I just don't know about or don't understand yet about the rewriting of the url or something similar?

0 Answers
Related