简体   繁体   中英

How to expose Treafik service status as HTTP endpoint?

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

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.

Example:

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.

You've tagged fastly so I'm presuming Fastly is the CDN you're using.

I'm responding specifically to the question:

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

Although I would expect Traefik to handle health check monitoring of its own backends, you could setup a health check for those backends within the CDN.

Here is an example, where I define two backends:

  • Traefik Backend (eg Backend A, Backend B etc)
  • Traefik Proxy (eg Traefik 1, Traffic 2 etc)

在此处输入图像描述

You also can see in the above image that I've added a health check to "Traefik Backend".

Below is some custom VCL that sets "Traefik Proxy" as the backend the CDN should send all incoming requests onto. It then checks if "Traefik Backend" is healthy, and if it isn't, then you can write whatever custom VCL is necessary to indicate that to the "Traefik Proxy" backend.

sub vcl_recv {
  #FASTLY recv
  
  // If there are multiple backends, then Fastly
  // will determine the backend dynamically.
  // So I set it explicitly to the Traefik proxy.
  set req.backend = F_Traefik_Proxy;
  
  // If the backend, that the Traefik proxy is calling, is unhealthy,
  // then do something else.
  if (!backend.F_Traefik_Backend.healthy) {
    // e.g. set a header for the Traefik proxy
  }
  
  return(lookup);
}

Here are some references that might be useful to you:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM