0%

traefik配置跨域策略

traefik配置跨域策略

Middleware

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: test-cors
namespace: default
spec:
headers:
customResponseHeaders:
Access-Control-Allow-Origin: "http://xxx.xx"
Access-Control-Allow-Methods: "*"
Access-Control-Allow-Headers: "*"
# 另一种写法
#accessControlAllowMethods:
# - "*"
#accessControlAllowOriginList:
# - "http://xxx.xx"
#accessControlAllowHeaders:
# - "*"
#accessControlMaxAge: 100
#addVaryHeader: true

ingress

在ingress中添加annotations就可以关联了

1
traefik.ingress.kubernetes.io/router.middlewares: default-test-cors@kubernetescrd

ingressroute

1
2
3
4
5
6
7
8
9
spec:
entryPoints:
- web
routes:
- kind: Rule
match: PathPrefix(`/api/xxx`)
middlewares:
- name: test-cors
namespace: default