【问题标题】:Installing 2 custom TLS Certs with Traefik / K8s使用 Traefik / K8s 安装 2 个自定义 TLS 证书
【发布时间】:2020-01-20 14:42:21
【问题描述】:

我有一个运行良好的 K8s 集群,其域具有自定义 SSL 证书,所有其他子域都使用 Let's encrypt 通配符。

现在,我想添加另一个将使用自定义 SSL 证书的域,但它似乎不起作用。

首先,我用.crt 和.key 文件创建一个configMap

kubectl create configmap traefik-sge-certificate --from-file=certificate/sge-prod.crt --from-file=certificate/sge-prod.key --dry-run -o yaml | kubectl apply -f -

然后我将我的证书添加到traefik.toml

traefik.toml:
----
# traefik.toml
defaultEntryPoints = ["http","https"]
[entryPoints]
  [entryPoints.http]
  address = ":80"
  [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]
      [[entryPoints.https.tls.certificates]]
      certFile = "/etc/ene-certificate/api.crt"
      keyFile = "/etc/ene-certificate/api.key"
      [[entryPoints.https.tls.certificates]]
      certFile = "/etc/sge-certificate/sge-prod.crt"
      keyFile = "/etc/sge-certificate/sge-prod.key"

[acme] # Automatically add Let's Encrypt Certificate.
  storage= "/etc/certificate/acme.json"
  email = "julien@company.fr"
   entryPoint = "https"
   onHostRule = true
   caServer = "https://acme-v02.api.letsencrypt.org/directory"
    [acme.dnsChallenge]
    provider = "route53"
    delayBeforeCheck = 0
[[acme.domains]]
  main = "*.company.fr"

现在部署:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: traefik-deployment
  labels:
    app: traefik
spec:
  replicas: 1
  selector:
    matchLabels:
      app: traefik
  template:
    metadata:
      labels:
        app: traefik
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
      volumes:
        - name: traefik-certificate
          persistentVolumeClaim:
            claimName: traefik-certificate
        - name: config
          configMap:
            name: traefik-config
        - name: traefik-ene-certificate
          configMap:
            name: traefik-ene-certificate
        - name: traefik-sge-certificate
          configMap:
            name: traefik-sge-certificate
      containers:
      - name: traefik
        image: "traefik:1.7"
        envFrom:
          - secretRef:
              name: traefik-env
        volumeMounts:
          - mountPath: "/etc/traefik/config"
            name: config
          - mountPath: "/etc/certificate"
            name: traefik-certificate
          - mountPath: "/etc/ene-certificate/api.crt"
            name: traefik-ene-certificate
            subPath: api.crt
          - mountPath: "/etc/ene-certificate/api.key"
            name: traefik-ene-certificate
            subPath: api.key           
          - mountPath: "/etc/sge-certificate/sge-prod.crt"
            name: traefik-sge-certificate
            subPath: sge-prod.crt
          - mountPath: "/etc/sge-certificate/sge-prod.key"
            name: traefik-sge-certificate
            subPath: sge-prod.key           

        args:
        - --configfile=/etc/traefik/config/traefik.toml
        - --api
        - --kubernetes

但是当我这样做时,有两个问题:

  • 我的新应用:https://sge.company.fr 正在使用通配符证书,而不是自定义证书(此操作的目的)
  • 使用自定义证书 api.crt(之前使用自定义 SSL 证书运行良好)的应用未使用通配符证书,这是一种回归。

我查看了traefik日志,似乎没有任何问题。

我也不明白,自定义 SSL 证书与域的链接在哪里。

谁能告诉我为什么会这样,我应该如何解决它?

PD:我知道我应该使用机密而不是 configMaps,但首先!

【问题讨论】:

    标签: ssl kubernetes traefik traefik-ingress


    【解决方案1】:

    我也不明白,自定义 SSL 证书与域的链接在哪里。

    证书是为特定域颁发的。所以,这里是链接。

    如果您为domain1.com 颁发证书,然后尝试在domain2.com 上使用它,Traefik 将无法安装它。

    我的错误是使用附加到我的证书的另一个域。

    所以,配置没问题,现在我可以使用我的自定义证书访问域

    希望对他人有所帮助

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      相关资源
      最近更新 更多