||1 year ago|
|.github/workflows||1 year ago|
|img||1 year ago|
|vendor||1 year ago|
|.gitignore||1 year ago|
|.traefik.yml||1 year ago|
|LICENSE||1 year ago|
|README.md||1 year ago|
|config.yml||1 year ago|
|config_dev.yml||1 year ago|
|docker-compose.yml||1 year ago|
|go.mod||1 year ago|
|go.sum||1 year ago|
|ondemand.go||1 year ago|
|ondemand_test.go||1 year ago|
|traefik.yml||1 year ago|
|traefik_dev.yml||1 year ago|
Traefik Ondemand Plugin
Traefik plugin to scale down to zero containers on docker swarm.
A container may be a simple nginx server serving static pages, when no one is using it, it still consume CPU and memory.
With this plugin you can scale down to zero when there is no request for the service. It will scale back to 1 when there is a user requesting the service.
The service whoami is scaled to 0. We configured a timeout of 10 seconds.
Run the demo
watch -n 1 docker service ls to see in real time the service getting downscaled
docker swarm init
docker stack deploy -c docker-compose.yml TRAEFIK_HACKATHON
- Go to
localhost:8000/whoami--> service is starting
- Refresh --> service is responding
- wait 10 seconds
- Refresh --> service is starting again because it was scaled down to 0
serviceUrlthe traefik-ondemand-service url (e.g. http://ondemand:10000)
namethe service to scale on demand name (docker service ls)
timeout(default: 60) timeout in seconds for the service to be scaled down to zero after the last request
docker-compose.yml for full configuration.
Cannot use service labels
You cannot set the labels for a service inside the service definition.
Otherwise when scaling to 0 the specification would not be found because there is no more task running. So you have to write it under the dynamic configuration file.
The need of "traefik-ondemand-service"
We are running "traefik-ondemand-service" to interact freely with the docker deamon and manage an independant lifecycle from traefik.
We may try to update this plugin to embed the scaling behavior in a future.
-> The source is available at https://github.com/acouvreur/traefik-ondemand-service
- Embed "traefik-ondemand-service" inside the plugin directly
- Scale up service (max replica, threshold)
- Scale down from N to 1 (threshold)
- Kubernetes integration
- Add configuration sample with plugin in non dev mode