-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Consider defining a helper "health check" utility for distroless scenarios #4300
Comments
[Triage] |
Does this affect Kubernetes' probes? I'm not 100% sure, but I think the probes commands are handled outside the container, so it must work even in a distroless environment. Is it correct? |
Not needed for Kubernetes. This is a docker compose need. |
As far as I understand, having a way to ping the application from within the container is very important in the AWS space for people (like me) using ECS instead of EKS. |
@mthalman: is there any news about this? I have a bunch of distroless ASP.NET Core apps running on my Raspi and I'd like to make use of a simple health check probe to http://localhost:8080/healthz in my |
There's been recent discussion on this as part of .NET 10 planning. Nothing is decided yet. But we recognize the interest in this feature. |
But for the moment, there is no alternative/hack, correct? |
We have a mini-healthcheck binary that we include in the container:
DOCKERFILE:
|
Thx for this hint, maybe that's a viable workaround for me 👍🏻 Since I'm using the .NET SDK Container Building Tools, I'd have to build an intermediary Docker base image (e.g. @mthalman: when discussing this particular feature internally, maybe it's worth taking this container publishing approach without an actual CC @baronfel |
I agree wholeheartedly with @mu88 . I also use the TBF/OT, the SDK approach needs to be extended to extra customization regardless of this or that approach. |
@baronfel - Does the SDK container publishing even have a means to define |
Of note, Healthcheck is only for Docker images and not OCI images. The OCI spec does have the healthcheck config item reserved, but only for compatibility with Docker images: https://github.com/opencontainers/image-spec/blob/5325ec48851022d6ded604199a3566254e72842a/media-types.md#applicationvndociimageconfigv1json |
We do not support HEALTHCHECK in any way in the SDK tooling (our issue discussing it was dotnet/sdk-container-builds#316). We chose not to specifically because OCI images (where the world is moving to) doesn't make use of them. |
MichelZ's approach inspired me. However, I decided against my first idea and didn't deploy my little health check tool via my Docker base image. Since I use several different .NET base images ( It took me a while to deploy both the health check assembly and the necessary That's not really nice, but so far I haven't found a solution for this (setting it to Anyhow, now it works properly with this services:
myservice:
container_name: mycontainer
image: mu88/myimage:latest-chiseled
healthcheck:
test: [ "CMD", "dotnet", "/app/mu88.HealthCheck.dll", "http://localhost:8080/healthz" ]
interval: 60s
timeout: 5s
retries: 3
start_period: 30s
start_interval: 5s If the community should be interested, I could also ship this component as a dedicated NuGet package. But for the moment, I keep it in my already existing package as I don't expect much interest in this niche feature. Thx again to @MichelZ for your input 🙏🏻 |
Glad you found a way to make things work! I think for cross-cutting tools like this the answer that other container platforms have settled on is making specific container layers with apps/diagnostic tooling/etc and then having the container publishing process slip-stream in those layers. Since a layer is just a file system tarball, practically speaking this means something like:
For arch-specific tools this would mean keeping a (signed and verified) inventory of per-RID Layer digests, etc. The SDK Container tooling would also need to implement dotnet/sdk-container-builds#325 to allow pointing to arbitrary Layers. So there's a decent amount of pre-work to get to this final state. |
I was also bothered on having to give up on healthchecks when using the chiseled images, so I made a docker image that contains a small AOT app, that can perform healthchecks. To overcome CPU architectures, I utilized docker's cross compilation, and I have tested it on a macbook (I don't have access to ARM github runners 😢). It works with any .NET 8+ image (even the minimum runtime-deps:*-chiseled-aot image) and it is zero config out of the box. Example: FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled AS final
# Get the executable and copy it to /healthchecks
COPY --from=ghcr.io/alexaka1/distroless-dotnet-healthchecks:1 / /healthchecks
# Setup the healthcheck using the EXEC array syntax
HEALTHCHECK CMD ["/healthchecks/Distroless.HealthChecks", "--uri", "http://localhost:8080/healthz"]
# Start your app as normal
WORKDIR /app
ENTRYPOINT ["dotnet", "My.Awesome.Webapp.dll"] |
The use of the
HEALTHCHECK
instruction often involves the use of a command that executes an HTTP request to the application in order to verify its health. That command might becurl
orwget
for Linux containers. This becomes problematic for distroless/chiseled containers that would likely want to exclude such commands. How then would a call be made to verify the health of the app?One solution is to include a basic .NET application that execute the HTTP request (see #4296). Depending on the ubiquity of such a solution, it might make sense for .NET to provide its own implementation of this application that can be easily injected into .NET distroless/chiseled solutions.
I'll illustrate this with an example. Let's say .NET publishes an
httpclient
image that contains a .NET app which simply sends an HTTP request to a URL provided as an argument. It returns 0 if the request succeeds and 1 if it fails. A distroless implementation could consume this app like the following:I think it'd be important to understand the landscape of how customers are using health checks to determine the suitability of a pre-defined tool like this. We obviously don't want to be reimplementing curl in .NET but allowing for a little bit of behavior customization in order to fulfill a large portion of customer scenarios seems reasonable.
The text was updated successfully, but these errors were encountered: