如何让 LetsEncrypt 在 Traefik 上使用通配符域?

How can I get LetsEncrypt working with a wildcard domain on Traefik?

我正在尝试在我的 Traefik 实例上使用通配符域设置 LetsEncrypt。已从 Helm Chart 安装 Traefik stable/traefik

我们正在为 DNS 使用 Google Cloud,所以我想使用 gcloud 作为我的 Traefik acme 提供商。

如前所述,这是一个通配符。我正在尝试让 Traefik 管理 *.domain.com 的 LetsEncrypt 和 domain.com 作为 SAN。

我目前正在使用 K8s 声明来存储 acme.json 文件,并且它已经填充了私钥但没有证书。

Traefik Helm 值

# LetsEncrypt
acme:
  acmeLogging: true
  challengeType: 'dns-01'
  enabled: true
  domains:
    enabled: true
    main: '*.<domain>'
    sans:
        - <domain>
  defaultEntryPoints:
  - http
  - https
  dnsProvider:
    name: 'gcloud'
    gcloud:
      GCE_PROJECT: <redacted>
      GCE_SERVICE_ACCOUNT_FILE: /secrets/gcloud-credentials.json
  email: <redacted>
  entryPoint: 'https'
  entryPoints:
    http:
      address: ':80'
    https:
      address: ':443'
  persistence:
    enabled: true
    existingClaim: 'certificate-store'
  provider: 'gcloud'
  staging: true

# SSL configuration
ssl:
 enabled: true
 enforced: true

acme.json

{
  "Account": {
    "Email": "<redacted>",
    "Registration": {
      "body": {
        "status": "valid",
        "contact": [
          "mailto:<redacted>"
        ]
      },
      "uri": "https://acme-staging-v02.api.letsencrypt.org/acme/acct/9091953"
    },
    "PrivateKey": "<redacted>",
    "KeyType": "4096"
  },
  "Certificates": null,
  "HTTPChallenges": {},
  "TLSChallenges": {}
}

来自 Traefik 的所有响应都应使用通配符 LetsEncrypt 证书提供给该域,该证书应自动续订。

我可能需要执行哪些额外步骤才能让 Traefik 开始生成证书,以及如何将 Traefik 配置为默认使用此证书? (而不是内置的)

谢谢

您是否 100% 确定 "domains" 节应该是这样的?在 stable/traefik 图表中,我略微看到另一种格式的域:

  domains:
    enabled: false
    # List of sets of main and (optional) SANs to generate for
    # for wildcard certificates see https://docs.traefik.io/configuration/acme/#wildcard-domains
    domainsList:
    # - main: "*.example.com"
    # - sans:
    #   - "example.com"
    # - main: "*.example2.com"
    # - sans:
    #   - "test1.example2.com"
    #   - "test2.example2.com"

但可能只是图表版本较新的问题,我不知道...如果您有较旧的图表版本,那么您可以尝试升级...

我想通了。 我在我的 Helm 图表中设置了以下内容(补充或替换以上内容)覆盖 YAML。

acme:
  caServer: 'https://acme-v02.api.letsencrypt.org/directory'
  domains:
    enabled: true
    domainsList:
      - main: '*.<domain>'
      - sans:
          - <domain>

我也摆脱了 persistence.existingClaim 并让 Traefik 做出自己的声明,但是如果您已经有一个现有的声明,那么保留这个定义应该不会给您带来任何问题!

所有 Traefik 入口现在都提供正确的 LetsEncrypt 证书,无需任何额外配置。

感谢 Vasily Angapov 的回复 - 您在 acme.domains.domainsList 部分的回答是正确的。 :-)