1

I have the ingress setup for Kubernetes as the following

    apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: dev-ingress
  #namespace: dev
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: "true"
    ingress.gcp.kubernetes.io/pre-shared-cert: "self-signed"
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/ingress.allow-http: "true"
spec:
  rules:
  - host: my.host.com
    http:
      paths:
      - backend:
          serviceName: webui-svc
          servicePort: 80
        path: /webui(/|$)(.*)

I am running an Angular app deployment under the webui-svc. The angular app is containerized using docker and I have included a Nginx configuration in the docker container like the following

    # Expires map
    map $sent_http_content_type $expires {
        default                    off;
        text/html                  epoch;
        text/css                   max;
        application/json           max;
        application/javascript     max;
        ~image/                    max;
    }
    
    server {
      listen 80;
      location / {
          root /usr/share/nginx/html;
          index index.html index.htm;
          try_files $uri $uri/ /index.html =404;
        }
      expires $expires;
      gzip  on;

}

When i am requesting for http://my.host.com/webui/ the internal calls are getting redirected without the webui prefixed to it for e.g

When i request for http://my.host.com/webui/ there are several calls made to get the main.js, vendor.js etc these all the requested via http://my.host.com/runtime.js so it fails, it would succeed if it would get redirected like http://my.host.com/webui/runtime.js

Is there a configuration in the angular application or the ingress that I am missing. Any help is very much appreciated, Thanks in advance

  • 1
    You may need to set the --base-href param during build (along with the answer from Tyzbit) – Drenai Apr 04 '21 at 09:22

1 Answers1

3

Your rewrite target is stripping off the /webui/. Consider your path:

path: /webui(/|$)(.*)

Now check the rewrite-target:

nginx.ingress.kubernetes.io/rewrite-target: /$2.

If you remove this annotation (and you can remove the use-regex annotation since it's now not needed), it will pass the /webui/ path onto your backend.

Tyzbit
  • 166
  • 2
  • The rewrite target is stripping off the /webui/ which is intended as the underlying service has root / and I have multiple services in the Ingress which are redirected based on the path eg `- backend: serviceName: webui-svc servicePort: 80 path: /webui(/|$)(.*) - backend: serviceName: media-svc servicePort: 80 path: /media-service(/|$)(.*)` So, it is needed. There has to be configuration that will append webui to the callbacks only for the webui svc and not for other rest svc like the media-svc a service without callbacks. – Saumadip Mazumder Apr 04 '21 at 11:39
  • Try changing the `path` to `/webui`. – Tyzbit Apr 04 '21 at 16:36
  • 2
    In that case, you could simply separate your services in two ingress definitions, one with the rewrite target, and one without it. Both Ingress can be served by the same Ingress Controller if they share the ingress class (and this means that they can share the same domain and so on) – AndD Apr 04 '21 at 20:22