Traefik 2.0 redirect middleware with Google Kubernetes Engine

12/3/2019

I'm trying to test and implement Traefik's https redirect feature in my kubernetes cluster per Traefik's documentation: https://docs.traefik.io/middlewares/overview/. Here's the definition of the Middleware and IngressRoute:

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

However, https://your.domain.name works and http://your.domain.name gives me a 404 page not found. Does anyone know what have I misconfigured ?

-- Deepak Garg
kubernetes
ssl
traefik
traefik-ingress

1 Answer

12/18/2019

that worked for me:

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
-- Julián Aguirre
Source: StackOverflow