【问题标题】:Traefik https redirect (via kubernetes deployment)Traefik https 重定向(通过 kubernetes 部署)
【发布时间】:2017-07-05 00:39:35
【问题描述】:

我正在通过 kubernetes 在 AWS 上运行 traefik。一切正常,除了我的 http=>https 重定向配置。

我有以下 .toml 文件

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
      entryPoint = "https"

使用下面的 Kubernetes 部署 + 服务配置。

https 请求工作文件,但 http 请求返回:

> curl http://www.myserver.com
curl: (52) Empty reply from server

Kubernetes 配置文件:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: traefik-proxy
  labels:
    app: traefik-proxy
    tier: proxy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: traefik-proxy
      tier: proxy
  template:
    metadata:
      labels:
        app: traefik-proxy
        tier: proxy
    spec:
      terminationGracePeriodSeconds: 60

      # kubectl create configmap traefik-conf --from-file=./conf/k8s/traefik.toml
      volumes:
      - name: config
        configMap:
          name: traefik-conf

      containers:
      - image: traefik:v1.2.0-rc1-alpine
        name: traefik-proxy
        resources:
          limits:
            cpu: "200m"
            memory: "30Mi"
          requests:
            cpu: "100m"
            memory: "20Mi"
        volumeMounts:
        - mountPath: "/conf"
          name: config
        ports:
        - containerPort: 80
          hostPort: 80
          name: traefik-proxy
        - containerPort: 8080
          name: traefik-ui
        args:
        - --configFile=/conf/traefik.toml
        - --kubernetes
        - --web
---
apiVersion: v1
kind: Service
metadata:
  name: traefik-proxy
  annotations:
    # SSL certificate.
    # https://console.aws.amazon.com/acm (alienlabs.io)
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:us-east-1:861694698401:certificate/28204a9f-69ec-424d-8f56-ac085b7bdad8"
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "http"
spec:
  type: LoadBalancer
  selector:
    app: traefik-proxy
    tier: proxy
  ports:
  - port: 80
    targetPort: 80
    name: http
  - port: 443
    targetPort: 80
    name: https

【问题讨论】:

    标签: kubernetes traefik


    【解决方案1】:

    我的traefik.toml 配置与Corey 的配置相似,但更简单一些。它适用于 httphttps 的全面重定向。

    defaultEntryPoints = ["http","https"]
    [entryPoints]
      [entryPoints.http]
      address = ":80"
        [entryPoints.http.redirect]
          entryPoint = "https"
      [entryPoints.https]
      address = ":443"
    

    【讨论】:

    • 感谢 Eugene -- 请参阅下面我对 Corey 的回复。
    【解决方案2】:

    您希望以稍微不同的方式声明您的入口点:

    defaultEntryPoints = ["http","https"]
    [entryPoints]
      [entryPoints.http]
      address = ":80"
        [entryPoints.http.redirect]
        regex = "^http://(.*)"
        replacement = "https://$1"
      [entryPoints.https]
      address = ":443"
    

    【讨论】:

    • 谢谢两位。我试过这个,但是myserver.com 请求被重定向到myserver.com:443,我得到 ERR_EMPTY_RESPONSE。你的k8s配置和我上面的一样吗?您是否使用 AWS 证书以便您的 ELB 进行终止?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 2022-01-12
    • 1970-01-01
    相关资源
    最近更新 更多