How to expose gRPC health check in headless .NET worker service?

76 Views Asked by At

I'm running a headless (i.e. no HTTP endpoints) .NET 8 worker service on k8s. I'd like to expose gRPC health checks which k8s can use for readiness/liveness probes. However, the examples only seem to cater for ASP.NET Core apps which do (also) provide HTTP endpoints:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddGrpc();
builder.Services.AddGrpcHealthChecks()
                .AddCheck("Sample", () => HealthCheckResult.Healthy());

var app = builder.Build();  // <-- this does not exist in the worker service

app.MapGrpcService<GreeterService>();
app.MapGrpcHealthChecksService();

The worker service obviously doesn't provide the WebApplicationBuilder but instead only a HostApplicationBuilder:

var builder = Host.CreateApplicationBuilder(args);

Any pointers how to expose this with minimum overhead are much appreciated!

0

There are 0 best solutions below