How to support the Kubernetes readiness/liveness probe with Ocelot API Gateway re-routes?

10/31/2018

I'm trying to use Ocelot as a gateway to a K8S cluster and ideally would like to use the readiness/liveness probes. But every way I try to get Ocelot to handle the probe's endpoint results in issues:

  1. If I don't create a reroute for it, Ocelot returns 404
  2. If I reroute the endpoint back to itself, Ocelot gets caught in an infinite loop
  3. If I reroute the endpoint to an existing location which isn't rerouted itself, Ocelot returns 404

Is there a way to make Ocelot allow access to an endpoint residing within the same service?

-- Chris Swinchatt
api-gateway
asp.net-core
c#
kubernetes
ocelot

1 Answer

11/9/2018

I found out how to do this. It's actually very simple, you just inject the MVC middleware earlier in the pipeline than the Ocelot middleware, and MVC will handle requests to internal endpoints before Ocelot ever sees them.

app.UseMvc();
app.UseOcelot().Wait();

Source: https://github.com/ThreeMammals/Ocelot/issues/681

-- Chris Swinchatt
Source: StackOverflow