<p>I am having .net a self-hosted application, basically, it runs for 12 hours. The entire functionality is working as expected in my local machine.</p>
<p>Reference:
<a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&amp;tabs=visual-studio" rel="nofollow noreferrer">Background tasks with hosted services in ASP.NET Core</a></p>
<p>Currently, we are using Kubernetes for deployment. While deploying it is checking the health status with the liveness endpoint and deployment is failing since there is no liveness endpoint as it is a background running application. To deploy the application in Kubernetes it is expecting the liveness endpoint.</p>
<p>Is there any way that we can serve some JSON data whenever the liveness endpoint is called from the docker side for the background running application?</p>
<p>Here is my docker code.</p>
<pre><code>FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 8080/tcp
CMD [&quot;dotnet&quot;, &quot;DarkTesting.WorkerService.dll&quot;]
</code></pre>

<p>Personally I have found that deploying my background services as ASP.NET Core applications works well, because we can:</p>
<ol>
<li>Deploy /health endpoints using <a href="https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-6.0" rel="nofollow noreferrer">Healthchecks</a></li>
<li>Use IHostedService for running the background services</li>
</ol>
