Træfɪk is a modern reverse proxy also written in Go. It supports multiple ways to get configured, this cookbook will explain how you can setup distributed Minio in Docker swarm which can be accessed inside swarm using a generic name (instead of minio1
, minio2
, ...) and expose Minio to the outside world with just one (loadbalanced) port through Træfɪk.
You have a running Docker swarm, if not head over to Docker Swarm mode overview.
Based on official Deploy Minio on Docker Swarm docs, we will deploy Minio using a Docker Compose file.
- strip the ports per Minio and add Træfɪk as loadbalancer in front of
- add Træfɪk labels (mind the
Host:...
label which configures the frontend rule where Træfɪk is listening for Swarm internal and external access) to each Minio service - add
minioproxy
Træfɪk service - Bonus: as we are using Docker swarm, we can also use secrets instead of environment variables (more secure)
Also see Minio Docker Quickstart Guide
echo "AKIAIOSFODNN7EXAMPLE" | docker secret create access_key -
echo "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | docker secret create secret_key -
Used for testing later.
docker network create --attachable --driver overlay minio_distributed
version: '3.1'
services:
minio1:
image: minio/minio:RELEASE.2017-05-05T01-14-51Z
volumes:
- minio1-data:/export
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
labels:
traefik.frontend.rule: "Host:minioproxy"
traefik.port: "9000"
command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
secrets:
- secret_key
- access_key
minio2:
image: minio/minio:RELEASE.2017-05-05T01-14-51Z
volumes:
- minio2-data:/export
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
labels:
traefik.frontend.rule: "Host:minioproxy"
traefik.port: "9000"
command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
secrets:
- secret_key
- access_key
minio3:
image: minio/minio:RELEASE.2017-05-05T01-14-51Z
volumes:
- minio3-data:/export
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
labels:
traefik.frontend.rule: "Host:minioproxy"
traefik.port: "9000"
command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
secrets:
- secret_key
- access_key
minio4:
image: minio/minio:RELEASE.2017-05-05T01-14-51Z
volumes:
- minio4-data:/export
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
labels:
traefik.frontend.rule: "Host:minioproxy,minio.example.com"
traefik.port: "9000"
command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
secrets:
- secret_key
- access_key
minioproxy:
image: traefik
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- minio_distributed
ports:
- 80:80
deploy:
placement:
constraints: [node.role == manager]
command: --docker --docker.swarmmode --docker.domain=minio --docker.watch --web
volumes:
minio1-data:
minio2-data:
minio3-data:
minio4-data:
networks:
minio_distributed:
external: true
secrets:
secret_key:
external: true
access_key:
external: true
docker stack deploy --compose-file=docker-compose.yaml minio_stack
Now we spin up a Minio mc test container on one of the Docker swarm nodes to access loadbalanced Minio using it's generic name.
docker run --rm -it --network minio_distributed --entrypoint=/bin/sh minio/mc
mc config host add minio http://minioproxy:80 AKIAIOSFODNN7EXAMPLE wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
mc mb minio/foo
mc ls minio
In this example, we configured Træfɪk with Host:minioproxy,minio.example.com
. So we need to have a dns record for minio.example.com
pointing to a ip address of any Docker swarm node or just add it to /etc/hosts
for a quick test. Then the test is like the internal one just using another hostname and NOT to be run on a swarm node:
docker run --rm -it --entrypoint=/bin/sh minio/mc
mc config host add minio http://minio.example.com:80 AKIAIOSFODNN7EXAMPLE wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
mc mb minio/bar
mc ls minio