【问题标题】:How can I create router and load balance service added to traefik via consulCatalog?如何通过 consulCatalog 创建添加到 traefik 的路由器和负载均衡服务?
【发布时间】:2021-11-23 22:57:13
【问题描述】:

我在裸机 2 个节点上运行 nextcloud:

node1: 192.168.1.10
node2: 192.168.1.11

在领事中,我在两个节点上都定义了 nextcloud 服务:

{
  "service": {
    "name": "nextcloud",
    "tags": ["nextcloud", "traefik"],
    "port": 80,
    "check": {
      "tcp": "localhost:80",
      "args": ["ping", "-c1", "127.0.0.1"], 
      "interval": "10s",
      "status": "passing",
      "success_before_passing": 3,
      "failures_before_critical": 3
    }
  }

现在这显示在领事罚款:

静态配置:traefik.yaml

global:
  # Send anonymous usage data
  sendAnonymousUsage: true

api:
  dashboard: true
  debug: true

log:
  level: DEBUG

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"

serversTransport:
  insecureSkipVerify: true

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
  file:
    directory: "/config/"
    watch: true
  consulCatalog:
    defaultRule: "Host(`{{ .Name }}.sub.mydomain.com`)"
    endpoint:
      address: http://127.0.0.1:8500

certificatesResolvers:
  linode:
    acme:
      caServer: https://acme-staging-v02.api.letsencrypt.org/directory
      email: myemail@domain.com
      storage: acme.json
      dnsChallenge:
        provider: linode
        resolvers:
          - "1.1.1.1:53"
          - "1.0.0.1:53"

然后动态/config/config.yaml:

http:
  routers:
    nextcloud@consulCatalog:
      entryPoints:
        - "https"
      rule: "Host(`home.sub.mydomain.com`) && Path(`/nextcloud`)"
      tls:
        certResolver: linode
      service: nextcloud

  services:
    nextcloud:
      loadBalancer:
        servers:
          - url: http://192.168.1.10
          - url: http://192.168.1.11
        passHostHeader: true

但这显示为带有 TLS 的文件提供程序,而不是现有的 consulcatalog 提供程序。

而不是 IP 或域映射。

显示了实际的 consulcatalog 提供程序,但没有 tls

我想知道为什么我在http中的动态配置没有更新nextcloud@consulcatalog并设置https入口点。

任何帮助将不胜感激,我正在努力让它发挥作用。 我曾尝试关注 traefik 上的文档,但在 consulcatalog 部分特别令人困惑。

【问题讨论】:

    标签: reverse-proxy traefik consul


    【解决方案1】:

    您的配置显示为通过文件提供程序定义,因为您在 /config/config.yaml 的文件中静态定义它。

    为了从 Consul 动态检索此配置,您不应定义静态配置文件,而应在 Consul 服务注册上配置标签,以指示 Traefik 将流量路由到您的服务。

    例如:

    {
      "service": {
        "name": "nextcloud",
        "tags": [
          "nextcloud",
          "traefik.enable=true",
          "traefik.http.routers.nextcloud.entrypoints=https",
          "traefik.http.routers.nextcloud.rule=(Host(`home.sub.mydomain.com`) && Path(`/nextcloud`))",
          "traefik.http.routers.nextcloud.tls.certresolver=linode",
          "traefik.http.services.nextcloud.loadbalancer.passhostheader=true"
        ],
        "port": 80,
        "check": {
          "tcp": "localhost:80",
          "args": [
            "ping",
            "-c1",
            "127.0.0.1"
          ],
          "interval": "10s",
          "status": "passing",
          "success_before_passing": 3,
          "failures_before_critical": 3
        }
      }
    }
    

    更多信息可以在 Routing Configuration 文档中找到 Traffic 的 Consul 目录提供者。

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 2018-12-27
      • 1970-01-01
      相关资源
      最近更新 更多