为什么Traefik v2仅通过http响应404

时间:2020-02-03 16:54:27

标签: kubernetes yaml traefik traefik-ingress

我的问题是我的kubernetes集群中的traefik入口控制器确实对404 page not found做出了http的响应,而对https做出了 BUT 的响应,我从服务。

这是在我将TLS部分添加到IngressRoute之后发生的。

这是我的IngressRoute:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: example-backend
  namespace: example
spec:
  entryPoints:
    - web
    - websecure
  routes:
  - match: Host(`api.example.com`)
    kind: Rule
    priority: 10
    services:
    - name: example-backend-service
      port: 80
  tls:
    secretName: tls-secret # I'm using my own certificate, not Let's Encrypt

为什么我没有得到像https这样的真实/相同的响应?

1 个答案:

答案 0 :(得分:2)

由于TLS适用于路由器,因此不能只有一个IngressRoute来处理这两种情况。

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: example-backend
  namespace: example
spec:
  entryPoints:
    - websecure
  routes:
  - match: Host(`api.example.com`)
    kind: Rule
    priority: 10
    services:
    - name: example-backend-service
      port: 80
  tls:
    secretName: tls-secret

---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: example-backend-redirect
  namespace: example
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`api.example.com`)
    kind: Rule
    priority: 10
    services:
    # in this IngressRoute the service will be never called
    # because of the redirect middleware.
    - name: example-backend-service
      port: 80
    middlewares:
    - name: https_redirect

---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: https_redirect
spec:
  redirectScheme:
    scheme: https
    permanent: true