Ocelot ApiGateway unable to reach other services on Kubernetes

3/22/2020

I'm working on a simple project to learn more about microservices.

I have a very simple .net core web with a single GET endpoint. I have added a ApiGateway web app with Ocelot, and everything seems to be working fine except when I deploy to a local Kubernetes cluster.

Those are the yaml files I'm using for the deployment:

ApiGateway.yaml

kind: Pod
apiVersion: v1
metadata:
  name: api-gateway
  labels:
    app: api-gateway
spec:
  containers:
    - name: api-gateway
      image: apigateway:dev

---

kind: Service
apiVersion: v1
metadata:
  name: api-gateway-service
spec:
  selector:
    app: api-gateway
  ports:
    - port: 80

TestService.yaml

kind: Pod
apiVersion: v1
metadata:
  name: testservice
  labels:
    app: testservice
spec:     
  containers:
    - name: testservice
      image: testbuild:latest

---

kind: Service
apiVersion: v1
metadata:
  name: testservice-service
spec:
  selector:
    app: testservice
  ports:
    - port: 80

ocelot.json

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/endpoint",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "testservice-service",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/test",
      "UpstreamHttpMethod": [ "Get" ]
    }
  ]
}

If I try to make a request with cUrl directly from the ApiGateway pod to the TestService service it works with no issue. But when I try to request it from Ocelot, it returns a 500 error, saying:

warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
  requestId: 0HLUEDTNVVN26:00000002, previousRequestId: no previous request id, message: Error Code: UnableToCompleteRequestError Message: Error making http request, exception: System.Net.Http.HttpRequestException: Name or service not known
   ---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known

Also, I tried with this https://ocelot.readthedocs.io/en/latest/features/kubernetes.html but honestly the doc is not really clear and I haven't had any success so far.

Any idea what the problem might be?

(I'm also using an Ingress resource for exposing the services, but that works with no problem so I will keep it out of this thread for now)

-- GioGio
api-gateway
asp.net-core
kubernetes
localhost
ocelot

0 Answers