How to read server status in load balancer service?


I'm trying to write a health check, which will monitor servers within the load balancer service.

I found one solution - add health check to the loadbalancer service, and then read status of each server using API and python script. Then I am able to expose URL, which will return HTTP code based on status of each server (for example 2XX if there is at least one server alive and 4XX or 5XX if all servers are down). Then, I want to connect this URL to external service, which will check this URL in some intervals and based on the return code, it will do some stuff.

Is there any better solution please?

Hi @FilipBursik55,
Thanks for your interest in Traefik.

I think your solution works.
In any case, there is no status aggregator in a load balancer.

Hi, Thank You for your reply. Is there a better way to expose service status as HTTP endpoint?

Hi @FilipBursik55,

Usually, health-checks are used in a load balancer to remove unhealthy servers from the selection process. In takes the form of an HTTP endpoint accessible from all the servers configured in your load balancer. This endpoint should return a 2xx-3xx status code. You can find in the service doc how to create this configuration.

After reading again your proposition, I think it does not fit into the current health-check configuration.

To give you an example, what we are doing in our apps, is to add an endpoint /health. This endpoint computes a status based on the application dependencies (boot up, db access, extra services access, ...) and sends it back to Traefik when it gets called.

Hope this helps, if not, could you explain a bit more your use case?


Hi, I'll try to explain it a little bit more.

I have multiple Traefik instances in different locations and a CDN. I need to configure the CDN to check the health of Traefik service to route traffic to.

Global CDN ----> Traefik 1
                            ---> Backend A
                            ---> Backend B
           ----> Traefik 2
                            ---> Backend C
                            ---> Backend D

I want to check the service has healthy backends. Checking the status/health of the Traefik instance itself is not enough.

Hello @FilipBursik55

Thanks for using Traefik and asking a question here.

In my opinion, if you external CDN running on the top of your stack I would consider using /ping health check probe that is built-in into Traefik. CDN should periodically check if Traefik is alive by calling that endpoint.
Once a request has been redirected by CDN to one of the Traefik instances, Traefik should periodically check if the backend is healthy. In that case, health check probes depend on the cluster orchestration tool you are using e.g. Docker or Kubernetes.

If you are on Kubernetes, you should configure health check probes (liveness and readiness) to validate what is the condition of the backend. If the backend is unhealthy and health check probes are configured, the Kubernetes endpoint won't be created and Traefik will not route requests to it.
For other configuration types (the file provider, Docker-based environment) please follow the docs.

However, if you would like to check the condition of the backend directly from CDN, you should create the appropriate routing on Traefik for the health check that is exposed by the backend e.g.