具有Google Kubernetes引擎的Traefik 2.0重定向中间件

时间:2019-12-03 07:46:27

标签: ssl kubernetes traefik traefik-ingress

我正在尝试根据Traefik的文档https://docs.traefik.io/middlewares/overview/在我的kubernetes集群中测试和实现Traefik的 https 重定向功能。这是MiddlewareIngressRoute的定义:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingressroutetls
  namespace: default
spec:
  entryPoints:
    - web
    - websecure
  routes:
  - match: Host(`your.domain.name`) && Host(`www.your.domain.name`)
    kind: Rule
    services:
    - name: traefik-dashboard
      port: 8080
    middlewares:
      - name: redirectscheme
  tls:
    secretName: cloud-tls
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: redirectscheme
spec:
  redirectScheme:
    scheme: https

但是, https ://your.domain.name有效,而 http ://your.domain.name给了我一个 404页面未找到< / em>。 有人知道我配置错误吗?

1 个答案:

答案 0 :(得分:0)

  对我有用的

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: a3-ing
  namespace: default
spec:
  entryPoints:
    - websecure
  routes:
  - match: Host(`example.com`)
    kind: Rule
    services:
    - name: whoami
      port: 80
  tls:
    certResolver: default
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: a3-ing-red
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`example.com`)
      middlewares:
        - name: test-redirectscheme
      kind: Rule
      services:
        - name: whoami
          port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: a3-ing-www
  namespace: default
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`www.example.com`)
      kind: Rule
      services:
        - name: whoami
          port: 80
  tls:
    certResolver: default
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: a3-ing-www-red
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`www.example.com`)
      kind: Rule
      middlewares:
        - name: test-redirectscheme
      services:
        - name: whoami
          port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: test-redirectscheme
  namespace: default  
spec:
  redirectScheme:
    scheme: https