3

Help!

I am using Istio to setup a service mesh in Kubernetes. The Virtual Service definition routes the traffic to the desired service:

(...)
  http:
  - match:
    - uri:
        prefix: /drill/
    rewrite:
      uri: /
    route:
    - destination:
        host: drill-service.drill.svc.cluster.local
        port:
          number: 8047

However, when calling the entrypoint

https://<HOST>:<NODEPORT_INGRESS_GW>/drill

I do see the HTML page, but the URLs are broken and CSS sheets are not loaded correctly. Reason is that the HTML source code points to the wrong targets:

li><a href="/storage">Storage</a></li>

instead of

li><a href="/drill/storage">Storage</a></li>

How can I fix this problem?

Thanks,

Matt

MBR
  • 33
  • 3

1 Answers1

2

When you use rewrite you need to add path in virtual service for your dependencies like css and js.

The whole process with rewrite and how it should be configured was well explained by @Rinor here.


This Istio in practise tutorial also explains it well.

Let’s break down the requests that should be routed to Frontend:

Exact path / should be routed to Frontend to get the Index.html

Prefix path /static/* should be routed to Frontend to get any static files needed by the frontend, like Cascading Style Sheets and JavaScript files.

Paths matching the regex ^.*.(ico|png|jpg)$ should be routed to Frontend as it is an image, that the page needs to show.

http:
  - match:
    - uri:
        exact: /
    - uri:
        exact: /callback
    - uri:
        prefix: /static
    - uri:
        regex: '^.*\.(ico|png|jpg)$'
    route:
    - destination:
        host: frontend             
        port:
          number: 80

Additionally you can take a look here.


EDIT

Why your example does not work

With your current virtual service your requests will be as follows:

http://www.page.com/drill/

Rewritten: http://www.page.com/


http://www.page.com/drill/storage

Rewritten: http://www.page.com/storage

So now you would have to either change virtual service configuration, for example for paths without rewrite or change your app dependencies location, so istio could actually see /drill/storage path with your current virtual service, for now it see /storage path , and there is nothing here as the real path is /drill/storage.

http:
  - match:
    - uri:
        prefix: /
    - uri:
        prefix: /drill/storage/
    - uri:
        prefix: /...

What I would suggest

If you have your domain configured as a virtual service host you might try with this virtual service:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: istio-vs
spec:
  hosts:
  - "drill.domain.com"
  gateways:
  - gateway
  http:
  - match:
    - uri:
        prefix: /
    rewrite:
      uri: /drill/
    route:
    - destination:
        host: drill-service.drill.svc.cluster.local
        port:
          number: 8047

With this virtual service your requests will be as follows:

http://www.page.com/

Rewritten: http://www.page.com/drill/


http://www.page.com/storage

Rewritten: http://www.page.com/drill/storage
Jakub
  • 8,189
  • 1
  • 17
  • 31
  • 1
    Hi Jakub, thanks for your answer, but this does not work (or I do not understand). I do see the examples on your references, but I have to extend the URL (adding drill) and not shorten as in the examples. After adding another URI the URLs are broken. Do I have to add rewrite-URI? – MBR Dec 09 '20 at 15:55
  • Hi @MBR I have edited my answer to explain to you why the current configuration does not work and what you might try to fix that. – Jakub Dec 10 '20 at 06:52
  • Hi Jakub, thanks for your answer. I do want the configuration other way around. Incoming requests http://www.page.com/drill should be routed to http://drill-service.drill.svc.cluster.local/ It seems to be very simple, but I do not find any reference of how to do this. Regards Matthias – MBR Dec 11 '20 at 12:31
  • @MBR Even if you use only `- match: - uri: prefix: /` it's gonna be routed to drill-service anyway, you specified that as your virtual service host. The point is with your current configurations you'r urls are bad configured and it won't work. – Jakub Dec 11 '20 at 12:42