Traefik Health Check
Traefik is a cloud-native application proxy which can be used as a Kubernetes ingress. If you’re planning to put a load balancer or something in front of your traefik instance, you may want to periodically health check your instance to make sure it’s up and ready to serve traffic. Traefik comes with a built in ping
endpoint for checking process liveness.
You can easily expose this using an IngressRoute
that points to the ping@internal
service. I chose to expose this as a subdomain, but you can expose it in any way that makes sense for your use case.
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ping
spec:
entryPoints:
- web
routes:
- match: Host(`health.example.com`)
kind: Rule
services:
- name: ping@internal
kind: TraefikService
Testing
Once configured, your IngressRoute should look something like this:
You should be able to curl the endpoint and get a 200 with a response body OK
.
$ curl health.example.com -v
* Rebuilt URL to: health.example.com/
* Trying xx.xx.xx.xx...
* Connected to health.example.com (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: health.example.com
> User-Agent: curl/7.48.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 30 Dec 2020 16:24:55 GMT
< Content-Length: 2
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host health.example.com left intact
OK