Skip to content

Instantly share code, notes, and snippets.

@dfang
Created November 1, 2020 03:18
Show Gist options
  • Save dfang/0e9a8f13b1d4b02f5a7302b3188c9f73 to your computer and use it in GitHub Desktop.
Save dfang/0e9a8f13b1d4b02f5a7302b3188c9f73 to your computer and use it in GitHub Desktop.
traefik IngressRoute
############
############
# REDIRECT TO HTTPS MIDDLEWARE
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: redirect-http-to-https
spec:
redirectScheme:
scheme: https
permanent: true
# HTTP (web endpoint) with redirect-to-https middleware
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: whoami
namespace: whoami
spec:
entryPoints:
- web
routes:
- match: Host("whoami.jdwl.in")
kind: Rule
services:
- name: whoami
port: 80
middlewares:
- name: http-redirect-to-https
# HTTPS (websecure endpoint)
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: whoami-https
namespace: whoami
spec:
entryPoints:
- websecure
routes:
- match: Host(`whoami.jdwl.in`)
kind: Rule
services:
- name: whoami
port: 80
tls:
secretName: wildcard-cert-prod
@dfang
Copy link
Author

dfang commented Nov 1, 2020

Global HTTP Redirect To HTTPS

如果是用helm chart安装的话:

values.yaml

service:
  labels:
    traefik.http.middlewares.https-redirect.redirectscheme.scheme: https
    traefik.http.routers.traefik-redirect.middlewares: "https-redirect"

效果:

http ingressroute 那里就不用加http-redirect-to-https 的middleware了
甚至都不用定义http ingressRoute了, 只需定义https 版的ingressRoute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment