Score:0

How to route all traffic to a service in Istio?

ke flag

I have a virtual service yaml file with below lines.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nodeserver
spec:
  hosts:
  - "*"
  gateways:
  - node-gateway
  http:
  - match:
    - uri:
        exact: /
    - uri:
        exact: /sample1
    - uri:
        exact: /sample2
    route:
    - destination:
        host: node-service
        port:
          number: 8080

Here, Instead of /sample1 and /sample2 as two url matches, can I assign something like * to route all traffic to node-service by default? Also, if the webpage has hyperlinks inside it will Istio redirect them by default or need to add any custom configuration for that?

Score:0
cn flag

Use prefix: ''

This worked for me:

  http:
  - match:
      - uri:
          prefix: ''
Score:0
us flag

You can use regex instead of exact in HTTPMatchRequest.
That way you can catch all with ECMAscript style regex.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nodeserver
spec:
  hosts:
  - "*"
  gateways:
  - node-gateway
  http:
  - match:
    - uri:
        regex: '.+'
    route:
    - destination:
        host: node-service
        port:
          number: 8080
uday avatar
ke flag
Thank you I will test that and reply back. Also, is there any way to set /page1 as default so that even if user types only istio gateway then it should route the traffic to /page1 also.
p10l avatar
us flag
You can use [HTTPRedirect](https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRedirect) or [HTTPRewrite](https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRewrite) to do that. This is however another question, and if you want a complete solution, you should post new question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.