Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Istio VirtualService - broken URLs

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

like image 343
MBR Avatar asked Nov 17 '25 10:11

MBR


1 Answers

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
like image 175
Jakub Avatar answered Nov 19 '25 07:11

Jakub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!