Expose app with Kubernetes NGINX Ingress Controller on subpath with no control over the basepath of the app

1/5/2020

I still can't wrap my head around the problem myself, so I'm not even sure if this is even possible. I cannot change my domain so I can only deploy my apps on subpaths via Ingress and not on subdomains, and I was able to deploy multiple apps by using a combination of nginx.ingress.kubernetes.io/rewrite-target: / and nginx.ingress.kubernetes.io/configuration-snippet: rewrite /<basepath>/(.*) /$1; for basepaths when I am able to control the basepath of the app, which is the case for e.g. the pgAdmin4 Docker-container (provides an ENV var), or apps I wrote myself.

Some applications however, like the Kubernetes Dashboard, k8dash or Kibana, do not provide a convenient option to specify the basepath in the k8s-Deployment object, and I couldn't get them to work.

The main problem seem to be paths like /assets/, /js/, /css/ etc.

I tried different versions with the rewrite path but I do not think this rewrites the content of my HTML, especially not if it is dynamically generated by js-frameworks like Angular.

Is there a sure-fire way to expose e.g. the Kubernetes-Dashboard or Kibana on a subpath, so that the deferred calls on the site are not resulting in 404?

PS: sorry if I couldn't articulate my problem in a way that makes it easy to answer the question, so if some inconsistencies or unknowns for anyone still exist, I would like to incorporate that into this question immediately. Thank you very much in advance.

PPS: I already tried like a 100 google search results and stackoverflow solutions I found, but still couldn't manage, so either my search skills are very poor, there is no solution for this or it is very hard to implement. One such though addresses a similar issue related to nginx itself but it did not help either

-- satanik
kubernetes
kubernetes-dashboard
nginx-ingress

1 Answer

1/5/2020

I encountered this problem as well and I found no way around it. If the web page of an application imports assets as you mentioned from /assets/* for example, and there's no config for a prefix in order to make it /app_prefix/assets/*, I don't see how it would be possible. You need that prefix in order to be able to determine to which application the request should be routed.

-- Radu Mazilu
Source: StackOverflow