alexus
July 12, 2022, 2:32am
1
Hello World!
I'm trying to configure the health check for the Traefik :
Traefik Ping Documentation - Traefik
Traefik Services Documentation - Traefik
So, I was able to configure health check for the service, but the to check for the health of my Traefik instances, not so much:
/ # traefik healthcheck
Error calling healthcheck: please enable `ping` to use health check
/ # traefik healthcheck --ping
INFO[0000] Configuration loaded from flags.
Bad healthcheck status: 404 Not Found
/ #
relevant options I used for Traefik to start up:
# grep ping docker-compose.yml
- "--entryPoints.ping.address=:8082"
- "--ping=true"
- "--ping.entryPoint=ping"
#
Please advise.
Thank you in advance)
Hello @alexus ,
What are you trying to achieve?
I've used the --ping
CLI argument.
- '--log.level=${TRAEFIK_LOG_LEVEL:-ERROR}'
- '--metrics.prometheus'
# Misc
- '--api.dashboard'
- '--entrypoints.websecure.http.middlewares=compress@file,headers@file${TRAEFIK_PLUGINS:-}'
- '--experimental.plugins.fail2ban.modulename=github.com/tommoulard/fail2ban'
- '--experimental.plugins.fail2ban.version=v0.6.0'
- '--global.checknewversion=${TRAEFIK_CHECK_NEW_VERSION:-false}'
- '--global.sendanonymoususage=${TRAEFIK_SEND_ANONYMOUS_USAGE:-false}'
- '--pilot.token=${TRAEFIK_PILOT_TOKEN:-}'
- '--ping'
- '--providers.file.directory=/dynamic_conf/'
- '--providers.file.watch=true'
ports:
- '${TRAEFIK_WEB_ENTRYPOINT:-80}:${TRAEFIK_WEB_ENTRYPOINT:-80}'
- '${TRAEFIK_WEBSECURE_ENTRYPOINT:-443}:${TRAEFIK_WEBSECURE_ENTRYPOINT:-443}'
networks:
- 'srv'
restart: always
healthcheck:
test: ['CMD', 'traefik', 'healthcheck', '--ping']
And a docker health check.
healthcheck:
test: ['CMD', 'traefik', 'healthcheck', '--ping']
interval: 10s
timeout: 10s
retries: 5
It correctly gets Traefik's health status.
If you want a more streamlined example, take a look at that:
version: '3.9'
services:
traefik:
image: traefik:v2.8
command:
- --ping
healthcheck:
test: ['CMD', 'traefik', 'healthcheck', '--ping']
volumes:
- /var/run/docker.sock:/var/run/docker.sock
alexus
July 12, 2022, 2:49pm
3
@tommoulard thank you for taking your time reply to my topic, i do appreciate that
the last example is very similar to the one I post initially w/ my topic along side with the output from it, and as you see it's not working( and I can't figure out what's wrong...
For me, my example is working as expected:
$ # I'm using the same docker-compose.yml file
$ docker compose up -d
[+] Running 2/2
⠿ Network test_default Created 0.0s
⠿ Container test-traefik-1 Started 0.5s
$ docker compose ps
NAME COMMAND SERVICE STATUS PORTS
test-traefik-1 "/entrypoint.sh --pi…" traefik running (starting) 80/tcp
$ sleep 10s
$ docker compose ps
NAME COMMAND SERVICE STATUS PORTS
test-traefik-1 "/entrypoint.sh --pi…" traefik running (healthy) 80/tcp
$ docker compose exec traefik traefik healthcheck --ping
INFO[0000] Configuration loaded from flags.
OK: http://:8080/ping
As you can see, the status goes from starting
to healthy
, and the CLI tool is working as expected.
alexus
July 12, 2022, 3:56pm
5
hmm, it worked for me ...
# docker compose exec traefik traefik healthcheck --ping
WARN[0000] network default: network.external.name is deprecated in favor of network.name
INFO[0000] Configuration loaded from flags.
OK: http://:8080/ping
#
.. once I've made some changes per your example:
# grep ping docker-compose.yml
#- "--entryPoints.ping.address=:8082"
- "--ping=true"
#- "--ping.entryPoint=ping"
#
I believe the issue is in the URL itself, as my ping was suppose to hit port 8082 , however per output it is hitting port 8080 instead..
glitch
February 19, 2023, 10:14am
6
You have to tell the healthcheck command which port to use, since you aren't using the default of 8080.
This should work: traefik healthcheck --entryPoints.ping.address=:8082 --ping
alexus
September 22, 2023, 1:30am
7
i'm just getting back to the same issue that i haven't finished since 7 month ago)) so that nobody say I never finish anything)))
# grep ping docker-compose.override.yml
- "--entryPoints.ping.address=:8082"
- "--ping.entryPoint=ping"
test: ["CMD-SHELL","traefik healthcheck --ping"]
# docker compose exec traefik traefik healthcheck --entryPoints.ping.address=:8082 --ping
INFO[0000] Configuration loaded from flags.
Bad healthcheck status: 404 Not Found
#
Not sure where
traefik healthcheck --ping
Is coming from, but I am sure that if you change the port
--entryPoints.ping.address=:8082
--ping.entryPoint=ping
you need to tell it the new port. Default is 8080. (Doc )
From traefik healthcheck --help
command:
--ping (Default: "false")
Enable ping.
--ping.entrypoint (Default: "traefik")
EntryPoint
--ping.manualrouting (Default: "false")
Manual routing
--ping.terminatingstatuscode (Default: "503")
Terminating status code
So you probably need to set the entrypoint for your healthcheck command.
alexus
September 22, 2023, 8:34pm
10
# grep ping docker-compose.override.yml
- "--entryPoints.ping.address=:8082"
- "--ping.entryPoint=ping"
test: ["CMD-SHELL","traefik healthcheck --ping"]
#
# docker compose exec traefik traefik healthcheck --ping --ping.entrypoint=ping
INFO[0000] Configuration loaded from flags.
Error calling healthcheck: ping: missing ping entry point
#
You want me to spell it out for you? Try:
test: ["CMD-SHELL","traefik healthcheck --ping.entrypoint ping --ping"]
alexus
September 22, 2023, 11:06pm
12
bluepuma77:
You want me to spell it out for you? Try:
test: ["CMD-SHELL","traefik healthcheck --ping.entrypoint ping --ping"]
i see where is confusion, i was trying to get it to run first at CLI level (hence showing you output) but you were reading my heathcheck instead, sorry about that i'll update to match the CLI, however I do get an error at CLI level, I assume same error would be via docker-compose' healthcheck as well.
I am rather confused by the heathcheck
itself It seems to require the Traefik API to be enabled (doc ).
In general the Docker mainstream uses curl
to implement the healthcheck (doc ) inside a container, but that’s not available in Traefik image.
ChatGPT thinks we can use included wget
this way (adapt URL):
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
alexus
September 23, 2023, 2:11pm
14
it is confusing and in my case i do have --api.insecure
enabled:
# grep -- --api docker-compose.override.yml
- "--api.insecure=true"
#
I also played with ChatGPT a bit as well: Configure Traefik with Docker-compose
time to test!!
This seems to work with Docker compose (in my case for Docker Swarm):
version: '3.9'
services:
traefik:
image: traefik:v2.10
hostname: '{{.Node.Hostname}}'
ports:
- target: 80
published: 80
protocol: tcp
mode: host
- target: 443
published: 443
protocol: tcp
mode: host
networks:
- proxy
- socket
volumes:
#- /var/log:/var/log
- letsencrypt:/letsencrypt
command:
- --api.dashboard=true
- --ping
- --log.level=INFO
#- --log.filepath=/var/log/traefik.log
- --accesslog=true
#- --accesslog.filepath=/var/log/traefik-access.log
- --providers.docker.swarmMode=true
- --providers.docker.network=proxy
- --providers.docker.exposedByDefault=false
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entryPoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.http.tls.certresolver=myresolver
- --certificatesresolvers.myresolver.acme.email=mail@example.com
- --certificatesresolvers.myresolver.acme.tlschallenge=true
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
deploy:
mode: global
placement:
constraints:
- node.role==manager
labels:
- traefik.enable=true
- traefik.http.routers.mydashboard.rule=Host(`traefik.example.com`)
- traefik.http.routers.mydashboard.service=api@internal
- traefik.http.routers.mydashboard.middlewares=myauth
- traefik.http.services.mydashboard.loadbalancer.server.port=1337
- traefik.http.middlewares.myauth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080/ping"]
interval: 30s
timeout: 3s
start_period: 5s
alexus
October 5, 2023, 8:49am
16
# grep ping docker-compose.override.yml
- "--ping=true"
test: ["CMD-SHELL","traefik healthcheck --ping"]
# docker exec -it traefik traefik healthcheck --ping
INFO[0000] Configuration loaded from flags.
OK: http://:8080/ping
#
system
Closed
October 8, 2023, 8:49am
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.