I tried to deploy google cAdvisor with traefik reverse proxy
Working nginx configuration
With nginx docker-compose:
cadvisor:
container_name: cadvisor
build:
context: .
dockerfile: projects/cadvisor/Dockerfile
command:
- '-port=80'
- '-url_base_prefix=/admin/cadvisor'
volumes:
- "/:/rootfs:ro"
- "/var/run:/var/run:ro"
- "/sys:/sys:ro"
- "/var/lib/docker:/var/lib/docker:ro"
- "/dev/disk:/dev/disk:ro"
expose:
- 80
Nginx configuration :
location ~* /admin/cadvisor/.*$ {
proxy_pass http://cadvisor;
}
Failed traefik configuration
cadvisor:
container_name:cadvisor
image: gcr.io/google-containers/cadvisor:latest
restart: always
privileged: true
networks:
- back-network
ports:
- "8080:8080"
command:
- '-url_base_prefix=/cadvisor'
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
labels:
- "traefik.http.routers.cadvisor.rule=Host(`localhost`) && PathPrefix(`/cadvisor`)"
- "traefik.http.services.cadvisor.loadbalancer.server.port=8080"
Main issue with cAdvisor is redirection, that's why we need to add url_base_prefix
arg
But previous docker-compose with traefik is not working
I don't know how to transpose location ~* /admin/cadvisor/.*$
to Traefik configuration
What do you do with Nginx there? Does it run on the host to handle other requests to another services? Nginx is not necessary for cAdvisor.
Here's a working example from my current installation:
The health check is a bit tricky, it is a fixed URL in the cAdvisor Dockerfile, but using the environment variable overwrites it. As you can see, I'm running cAdvisor with the path /cadvisor/, so I had to add this as command option "--url_base_prefix" and to modify the CADVISOR_HEALTHCHECK_URL environment variable.
Traefik runs as reverse proxy, it listens on Port 443 and 80, I didn't want to open another port like 8080 to the public, so Traefik is responsible to handle the TLS stuff and redirects from http to https. So you DON'T need to open port 8080 or expose port 80 in your cAdvisor definition! This will be handled by Traefik. Traefik reaches your containers by using the same Docker network.
Beware of priority settings! If another Traefik service handles the root URL, it must have a lower priority. Otherwise your service definition will never be matched.
If it is not allowed to post URLs, I apologize, but maybe it's useful for somebody. I've written introduction articles on https://www.kuerbis.org/traefik-und-mehr/ - in one of them you will find more about Traefik and cAdvisor. They are written in German, but I guess Google Translate or similar should help.
Kind regards, Ralf