Services don't communicate in Istio service mesh

10/15/2018

I have service mesh with two services(Service1 and Service2). Sidecars enabled. I've used the basic gateway from bookinfo official Istio tutorial and have configured VirtualService:

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: virtual-template-service
spec:
  gateways:
  - bookinfo-gateway
  hosts:
  - "*"
  http:
  - match:
    - uri:
        prefix: /api/home/method1
    - uri:
        prefix: /api/home/method2
    route:
    - destination:
        host: service1.service1-production.svc.cluster.local
        port:
          number: 80
  - match:
    - uri:
        prefix: /api/home2
    route:
    - destination:
        host: service2.service2-production.svc.cluster.local
        port:
          number: 80


apiVersion: v1
kind: Service
metadata:
  labels:
    app: {{ .Chart.Name }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: app
  name: {{ .Release.Name }}
spec:
  ports:
  - name: http
    port: {{ .Values.service.port }}
    protocol: TCP
    targetPort: {{ .Values.service.port }}
  selector:
    app: {{ .Chart.Name }}
    release: {{ .Release.Name }}
    component: app
  sessionAffinity: None
  type: ClusterIP

method1 of Service1 does not interact with the Service2. When I request Service1/api/home/method1. Everything works fine.

method2 of Service1 does interact with Service2. It sent a simple async HTTP request by a POST method. And this method does not work.

In the sidecar logs of Service1 I see that request was sent, but the status is 500. And in app logs, I see the error: No such address or device.

In the Service2 sidecar, the logs don't have any activity.

Request to service2/api/home2 works fine too.

I don't understand what I am doing wrong. What do you think about it? Please help.

UPDATE

Both application based on .net core. So i use webclient for sending requests. Example:

public static async Task<string> RequestToService2Async(string request)
        {
            using (var client = new WebClient())
            {
                client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                var response = await client.UploadStringTaskAsync(new Uri(http://service2/api/home2), "POST", request);
                return response;
            }
        }

Service1 side-car logs:

 "GET /api/home/method2HTTP/1.1" 500 - 0 0 28 5 "20.100.3.1" "PostmanRuntime/7.3.0" "083fbcbc-9598-9973-b0c1-b897afdc9df0" "Service1" "127.0.0.1:80" inbound|80||Service1.Service1-production.svc.cluster.local - 20.100.3.110:80 20.100.3.1:0 outbound|80||Service1.Service1-production.svc.cluster.local

ERROR in app logs

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLHJ7PTBHFRI", Request id "0HLHJ7PTBHFRI:00000002": An unhandled exception was thrown by the application.
System.Net.WebException: No such device or address No such device or address ---> System.Net.Http.HttpRequestException: No such device or address ---> System.Net.Sockets.SocketException: No such device or address
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at System.Net.HttpWebRequest.SendRequest()
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

UPDATE 2.0

When i use in Uri MyService2ClusterIP/api/home2 - everything works! So, i just can't do request with host name in uri.

-- Шебалов Денис
istio
kubernetes

0 Answers