Skip to main content

Kubernetes- How adding healthchecks made our applications less resilient

When using a container orchestrator like Kubernetes it is recommended to add health check probes to your application. These health probes can be used to check the app’s status and help the container orchestrator decide when to restart a container, start sending traffic, …

So we decided to use the Microsoft.AspNetCore.Diagnostics.HealthChecks package to add a healthcheck endpoint to our ASP.NET Core applications:

Inside the health check, we test our app dependencies to confirm availability and normal functioning. So far, so good…

Unfortunately we went a little bit too far with this approach which got us into trouble. What did we do wrong?

Therefore I need to explain a little bit about our architecture. We use an API gateway as the single entry point for all of our services:

This API gateway is just another ASP.NET Core Application that is using GraphQL schema stitching to bring all our API’s together in one logical schema. And of course we also added a healthcheck endpoint here:

Inside this health check, we check the availability of all the other services. And that is were we got ourselves into trouble. Because now, even when one less important service becomes unavailable, the whole API gateway is marked as unhealthy and becomes unavailable. So instead of making our system more resilient, introducing health checks made our system less resilient. Whoops!

Dumb and smart health checks

The solution is to first of all distinguish between dumb and smart health checks:

  • Smart probes check that an application is working correctly, that it can service requests, and that it can connect to its dependencies (a database, message queue, or other API, for example).
  • Dumb probes check only indicate the application has not crashed. They don't check that the application can connect to its dependencies.

Also think about what dependencies are necessary for a service to be available. Does a service is no longer usable when your logging infrastructure is temporary unavailable? In our case this would avoided our mistake to include all our services in the API gateway health check.

When you are using Kubernetes as your container orchestrator, a third tip could be added to the list. Kubernetes doesn’t have one healthcheck probe but has 3, which are used for different purposes:

  • Liveness probe. This is for detecting whether the application process has crashed/deadlocked. If a liveness probe fails, Kubernetes will stop the pod, and create a new one.
  • Readiness probe. This is for detecting whether the application is ready to handle requests. If a readiness probe fails, Kubernetes will leave the pod running, but won't send any requests to the pod.
  • Startup probe. This is used when the container starts up, to indicate that it's ready. Once the startup probe succeeds, Kubernetes switches to using the liveness probe to determine if the application is alive.

So instead of adding just one healthcheck endpoint to your ASP.NET Core application, I would recommend to configure at least the startup and liveness probes where I would setup the liveness probe to be a ‘dumb’ probe and the startup probe to be a ‘smart’ probe.

Popular posts from this blog

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

VS Code Planning mode

After the introduction of Plan mode in Visual Studio , it now also found its way into VS Code. Planning mode, or as I like to call it 'Hannibal mode', extends GitHub Copilot's Agent Mode capabilities to handle larger, multi-step coding tasks with a structured approach. Instead of jumping straight into code generation, Planning mode creates a detailed execution plan. If you want more details, have a look at my previous post . Putting plan mode into action VS Code takes a different approach compared to Visual Studio when using plan mode. Instead of a configuration setting that you can activate but have limited control over, planning is available as a separate chat mode/agent: I like this approach better than how Visual Studio does it as you have explicit control when plan mode is activated. Instead of immediately diving into execution, the plan agent creates a plan and asks some follow up questions: You can further edit the plan by clicking on ‘Open in Editor’: ...