Host name resolution for backend service on Anthos Service Mesh with Istio ingress-gateway

169 views Asked by At

I have a Node/React application that I am running on an Anthos Service Mesh/GKE with an Istio ingress-gateway. Here is my gateway yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: client-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - '*'
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: client-ingress
spec:
  hosts:
    - '*'
  gateways:
    - client-gateway
  http:
    - match:
        - uri:
            prefix: /posts/create
      route:
        - destination:
            host: posts-srv # 2
            port:
              number: 4000
    - match:
        - uri:
            prefix: /posts
      route:
        - destination:
            host: query-srv # 2
            port:
              number: 4002
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: client-srv # 2
            port:
              number: 80

My React app makes 3 api calls which are

posts.com/posts, 
posts.com/posts/create, 
posts.com/posts/comments/*

As it is now I get timeout errors whenever I make an api call. If I replace the posts.com/ with the IP address to the load balancer in the api calls from the React app the application works, like this

34.258.xxx.xxx/posts,
34.258.xxx.xxx/posts/create
34.258.xxx.xxx/posts/comments/*

I tried chaging the hosts field in the yaml to posts.com and adding posts.com with the load balancer IP to my hosts file for the resolution but that doesn't work either.

How can I make it so just going to posts.com in my browser will let me use the application without having to hardcode the IP addresses into the api calls in the React app?

Any help is greatly appreciated, thank you.

1

There are 1 answers

0
Curtis Botonis On

Nevermind, I just pointed my personal domain name to the load balancers ip, updated the domain name into the API calls and it is working as intended. Using GKE with GCE ingress I was able to update my host file to just use posts.com but I guess istio ingress-gateway does not allow that.