分类目录

链接

2023 年 7 月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > Docker > 正文
traefik负载均衡/滚动升级
Docker 暂无评论 阅读(93)

docker-compose.yml

version : '3'
services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.10
    # Enables the web UI and tells Traefik to listen to docker
    command: 
      # insecure
      - --api.insecure=true 
      - --providers.docker
      # Create an entrypoint "http" listening on port 80
      - --entrypoints.http.address=:80
      # Create an entrypoint "https" listening on port 443
      - --entrypoints.https.address=:443
      - --providers.file.directory=/etc/traefik/
      - --providers.file.watch=true
    ports:
      # The HTTP port
      - "80:80"
      - "443:443"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik/:/etc/traefik/

  whoami:
    # A container that exposes an API to show its IP address
    image: traefik/whoami
    ports:
      - "8081:80"
    labels:
      - "traefik.http.routers.whoami.rule=Host(`hk.peos.cn:8081`)"
  whoami2:
    # A container that exposes an API to show its IP address
    image: traefik/whoami
    ports:
      - "8082:80"
    labels:
      - "traefik.http.routers.whoami.rule=Host(`hk.peos.cn:8082`)"

 

./traefik.yml:

http:
  routers:
    prod-router:
      rule: "Path(`/prod`)"
      service: load-service
    
  services:
    load-service:
      loadBalancer:
        healthCheck:
          path: /health
          interval: 2s
          timeout: 2s
        servers:
        - url: "http://hk.peos.cn:8082/"
        - url: "http://hk.peos.cn:8081"

tls:
  certificates:
    - certFile: "/etc/certs/hk.peos.cn.cer"
      keyFile: "/etc/certs/hk.peos.cn.key"

 

publish.sh

echo upgrade api-1
docker-compose stop api-1
docker-compose rm -f api-1
docker-compose build --no-cache api-1
docker-compose up -d api-1
sleep 10

echo upgrade api-2
docker-compose stop api-2
docker-compose rm -f api-2
docker-compose build --no-cache api-2
docker-compose up -d api-2

echo success

 

corresponding errors:

  1. traefik file watch not working in docker (Traefik only support directory and must mounted a folder to container.)

 

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:traefik负载均衡/滚动升级 | Bruce's Blog

发表评论

留言无头像?