Host matching not working in istio gateway

2/11/2019

I followed this tutorial to install istio and also deployed the sample bookinfo app.

They have the following ingress-gateway.yml file

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: bookinfo-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "*"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage
        port:
          number: 9080

When I do kubectl apply -f ingress-gateway.yml, it works perfectly fine and I can access the application on http://<ip>/productpage

However, if I want to access it on a specific domain e.g. bookinfo.com

I changed the hosts field in both the gateway and VirtualService section and added an entry in my /etc/hosts file.

So, it changed to the following

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: bookinfo-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "bookinfo.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "bookinfo.com"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage
        port:
          number: 9080

When I try to access http://bookinfo.com/productpage, it gives a 404 not found. What am I missing?

PS: I am using istio1.0.5

-- kosta
gateway
google-kubernetes-engine
istio

2 Answers

2/13/2019

You already set the route to the path /productpage, then Your destination.host in your VirtualService should match your VirtualService name in your case is "bookinfo"

Then run the curl command

curl -I -HHost:bookinfo.com http://$INGRESS_HOST:$INGRESS_PORT/productpage

Note that you use the -H flag to set the Host HTTP Header to “bookinfo.com”. This is needed because your ingress Gateway is configured to handle “bookinfo.com”.

-- Alioua
Source: StackOverflow

2/12/2019

If you are doing curl http://bookinfo.com/productpage, it would work only if you've done hosts file entry for that ip address.

Or a better way to do is explicitly sending header in your curl request:

curl <ip:port>/productpage --header 'Host: bookinfo.com'

If you are still not able to do it, let me now.

-- murarisumit
Source: StackOverflow