Istio ingress gateway subdomainrouting based

5/21/2021

I have three service that I need to expose via istio ingress gateway, i have setup those services dns records to point to the ingress gateway load balancer but i have not succeded to make it work.

The gateway and virtual service config file :

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: test-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*.mywebsite.io"


    
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtualservice
spec:
  hosts:
  - "*.mywebsite.io"
  gateways:
  - test-gateway
  http:
  - name: "api-gateway"
    match:
    - uri:
        exact: "gateway.mywebsite.io"
    route:
      - destination:
           host: gateway.default.svc.cluster.local
           port:
             number: 8080
  - name: "visitor-service"
    match:
    - uri:
        exact: "visitor-service.mywebsite.io"
    route:
      - destination:
           host: visitor-service.default.svc.cluster.local
           port:
             number: 8000
  - name: "auth-service"
    match:
    - uri:
        exact: "auth-service.mywebsite.io"
    route:
      - destination:
           host: auth-service.default.svc.cluster.local
           port:
             number: 3004  

     
-- Abdnacer Fried
istio
istio-gateway
kubernetes

1 Answer

5/21/2021

I guess the URI part of the HttpMatchRequest does not work that way. Try to add VirtualServices for each subdomain, i.e. something like.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: gateway-virtualservice
spec:
  hosts:
  - "gateway.mywebsite.io"
  gateways:
  - test-gateway
  http:
  - name: "api-gateway"
    match:
    - uri:
        exact: "/" #or prefix
    route:
      - destination:
           host: gateway.default.svc.cluster.local
           port:
             number: 8080
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: visitor-virtualservice
spec:
  hosts:
  - "visitor-service.mywebsite.io"
  gateways:
  - test-gateway
  http:
  - name: "visitor-service"
    match:
    - uri:
        exact: "/"
    route:
      - destination:
           host: visitor-service.default.svc.cluster.local
           port:
             number: 8000
-- user140547
Source: StackOverflow