简体   繁体   中英

Traefik: Bad Gateway in Swarm Mode deployed on Azure

I'm currently trying to deploy a set of microservices using Docker Swarm Mode. I've set up a traefik container and all my containers like this:

version: "3.4" 
networks:
  backend-network:
    external: true
services:     

  proxy:
    image: traefik
    command: --api --docker --docker.swarmMode --docker.watch
    networks: 
      - backend-network 
    ports: 
      - "80:80"
      - "8090:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy: 
      replicas: 1
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.role == manager

  front-end:
    image: *****
    env_file:
      - ./env/.react.env
    networks: [ "backend-network" ]
    ports: 
      - "8080:80"
    deploy: 
      labels:
        - traefik.enable=false
      replicas: 1
      restart_policy: 
        condition: on-failure
      placement:
        constraints:
          - node.role == manager

  users-db:
    image: *****
    networks: ["backend-network"]
    ports: [ "5984:5984" ]
    deploy:
      labels:
        - traefik.enable=false
      replicas: 1
      restart_policy: # restart if something went wrong
        condition: on-failure

  # server that listens HTTP requests
  users:
    image: *****
    env_file: 
      - ./env/.users.env
    # wait until service db is up
    depends_on: [ "users-db" ]
    networks: 
      - backend-network
      # - proxy
    # expose port 80 of host node
    expose:
      - "80"
    deploy:   
      labels:
        - traefik.port=80
        - traefik.docker.network=backend-network
        - traefik.frontend.rule=PathPrefixStrip:/api/auth/
        - traefik.backend.loadbalancer.swarm=true
        - traefik.backend.loadbalancer.stickiness=true
      replicas: 1


  shop:
    image: *******
    env_file: 
      - ./env/.shop.env
    depends_on: [ "users"]
    networks:
      - backend-network
      # - proxy
    expose:
      - "80"
    deploy:
      labels:
        - traefik.port=80
        - traefik.frontend.rule=PathPrefixStrip:/api/shop
        - traefik.docker.network=backend-network
        - traefik.backend.loadbalancer.swarm=true
        - traefik.backend.loadbalancer.stickiness=true
      replicas: 1


  checkout:
    image: *****
    env_file: 
      - ./env/.checkout.env
    depends_on: [ "users", "shop" ]
    networks:
      - backend-network
    expose:
      - "80"
    deploy:
      labels:
        - traefik.port=80
        - traefik.frontend.rule=PathPrefixStrip:/api/checkout
        - traefik.docker.network=backend-network
        - traefik.backend.loadbalancer.swarm=true
        - traefik.backend.loadbalancer.stickiness=true
      replicas: 1


  visualizer:
    image: dockersamples/visualizer:stable
    ports: [ "9000:8080" ]
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      labels: 
        - traefik.enable=false
      placement:
        constraints:
          - node.role == manager

I hid the image names with ****.

I created two VM's on Azure, I created the Swarm, Traefik discovers my services but when I try to make a request with azure-dns/api/shop for example, it always returns Bad Gateway.

When using docker-compose up in local, it works fine. I did not try a Docker Swarm in local with docker-machine yet. I will soon.

Verify that backend-network is an overlay network.

Then try first without

   - traefik.backend.loadbalancer.swarm=true
   - traefik.backend.loadbalancer.stickiness=true # especially this one

It seems that sticky session is buggy in v1.7 according to issue 3770.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM