在阅读Traefik文档时,当我面对the documentation中提到的配置框架时感到困惑:
traefik.toml:
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
# ...
[entryPoints.https]
# ...
[file]
# rules
[backends]
[backends.backend1]
# ...
[backends.backend2]
# ...
[frontends]
[frontends.frontend1]
# ...
[frontends.frontend2]
# ...
[frontends.frontend3]
# ...
# HTTPS certificate
[[tls]]
# ...
[[tls]]
# ...
将配置文件中的规则部分分为backend
和frontend
两个不同的子部分的原因是什么?
答案 0 :(得分:1)
如果不将其划分为后端和前端,即使配置了多个服务,我也无法将多个服务连接到同一个后端,因此具有负载平衡功能。
version: '3.2'
services:
minio1:
image: minio/minio:RELEASE.2018-11-30T03-56-59Z
hostname: minio1
volumes:
- minio1-data:/export
ports:
- target: 9000
mode: host
networks:
- minio_distributed
- webgateway
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
labels:
- traefik.enable=true
- traefik.docker.network=webgateway
- traefik.backend=minio
- traefik.frontend.rule=Host:minio.mycooldomain.com
- traefik.port=9000
placement:
constraints:
- node.labels.minio1==true
command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
secrets:
- secret_key
- access_key
minio2:
image: minio/minio:RELEASE.2018-11-30T03-56-59Z
hostname: minio2
volumes:
- minio2-data:/export
ports:
- target: 9000
mode: host
networks:
- minio_distributed
- webgateway
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
labels:
- traefik.enable=true
- traefik.docker.network=webgateway
- traefik.backend=minio
- traefik.frontend.rule=Host:minio.mycooldomain.com
- traefik.port=9000
placement:
constraints:
- node.labels.minio2==true
command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
secrets:
- secret_key
- access_key
volumes:
minio1-data:
minio2-data:
minio3-data:
minio4-data:
networks:
minio_distributed:
driver: overlay
webgateway:
external: true
secrets:
secret_key:
external: true
access_key:
external: true
这是我的一个示例,其中“ minio1”和“ minio2”服务可通过同一域访问。通常,只要我拥有不同的服务,每个服务都会自动获得自己的后端,并且我不得不为每个服务提供自己的域,并且只有一个服务可以扩展数量,这些其他容器才能在同一个域中访问。
希望我能用自己的经验来解释一下。 :) 请注意,我什至拥有4个minio服务,我只是将其剪裁以缩短配置