我可以将 Traefik 对仪表板的默认 api 路径从/api
更改为其他路径吗?不幸的是,我发现此链接不再有效。
在我的场景中,Traefik 充当 Kubernetes 入口控制器,我使用的是基于路径的路由。现在的问题是我无法将/api
用于我自己的微服务,因为仪表板已经使用此路径(这些终结点(。
仪表板的入口配置:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-web-ui
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/priority: "2"
spec:
rules:
- http:
paths:
- path: /dashboard
backend:
serviceName: traefik-web-ui
servicePort: http
- path: /api <-- needed to make dashboard's api available
backend:
serviceName: traefik-web-ui
servicePort: http
其中一个微服务的入口配置:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: backend
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/priority: "999"
spec:
rules:
- http:
paths:
- path: /apis/ <-- i'd rather use /api here
backend:
serviceName: {{ include "my-backend.fullname" . }}
servicePort: http
您可以按如下方式自定义它
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.foo]
address = ":8080"
[entryPoints.bar]
address = ":8081"
# Activate API and Dashboard
[api]
entryPoint = "bar"
dashboard = true
[file]
[backends]
[backends.backend1]
[backends.backend1.servers.server1]
url = "http://127.0.0.1:8081"
[frontends]
[frontends.frontend1]
entryPoints = ["foo"]
backend = "backend1"
[frontends.frontend1.routes.test_1]
rule = "PathPrefixStrip:/yourprefix;PathPrefix:/yourprefix"
来自 Traefik 的相应文档在这里