1.默认证书
apiVersion: traefik.containo.us/v1alpha1
kind: TLSStore
metadata:
name: default
namespace: default
spec:
defaultCertificate:
secretName: default-certificate
---
apiVersion: v1
kind: Secret
metadata:
name: default-certificate
namespace: default
type: Opaque
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0=
2.Middleware
2.1 http转https
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: redirect-https
namespace: test
spec:
redirectScheme:
scheme: https
2.2 指定带路径的域名
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: common-api-gateway
namespace: test
spec:
stripPrefix:
prefixes:
- "/api/"
2.3 TLSoption
apiVersion: traefik.containo.us/v1alpha1
kind: TLSOption
metadata:
name: mintls12
namespace: nginx-test
spec:
minVersion: VersionTLS12
2.4 不同域名跳转
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: rewriteurl
namespace: test
spec:
redirectRegex:
regex: ^https://test.com/(.*)
replacement: https://www.test.com/${1}
3.IngressRoute
3.1 http
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingress-common-http
namespace: test
spec:
entryPoints:
- web
routes:
- kind: Rule
match: Host(`nginx.test.com`) && PathPrefix(`/`)
services:
- name: nginx-test1-service
port: 80
- kind: Rule
match: Host(`nginx.test.com`) && PathPrefix(`/api/`)
services:
- name: nginx-test2-service
port: 8080
middlewares:
- name: "common-api-gateway"
- name: redirect-https
3.2 https
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingress-common-https
namespace: test
spec:
entryPoints:
- websecure
routes:
- kind: Rule
match: Host(`nginx.test.com`) && PathPrefix(`/`)
services:
- name: nginx-test1-service
port: 80
- kind: Rule
match: Host(`nginx.test.com`) && PathPrefix(`/api/`)
services:
- name: nginx-test2-service
port: 8080
middlewares:
- name: "common-api-gateway"
tls:
secretName: nginx-test
options:
name: mintls12