英文:
Traefik Dashboard - custom API path
问题
可以更改Traefik仪表板的默认API路径从/api
到其他路径吗?我找到了这个链接,但不幸的是它不再可用。
在我的情况下,Traefik充当Kubernetes Ingress控制器,并且我正在使用基于路径的路由。问题是现在我不能使用/api
来供我的微服务使用,因为仪表板已经使用了这个路径(这些端点)。
仪表板的Ingress配置:
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 <-- 需要使仪表板的API可用
backend:
serviceName: traefik-web-ui
servicePort: http
一个微服务的Ingress配置:
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/ <-- 我更愿意在这里使用/api
backend:
serviceName: {{ include "my-backend.fullname" . }}
servicePort: http
英文:
Can I change Traefik's default api path for the dashboard from /api
to something else? I found this link which is not working anymore, unfortunately.
Traefik is acting as Kubernetes ingress controller in my scenario and I'm using path-based routing. The problem is now that I cannot use /api
for my own microservices because the dashboard uses this path already (these endpoints).
Ingress configuration for the dashboard:
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
Ingress configuration for one of the microservices:
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
答案1
得分: 1
以下是翻译好的部分:
你可以按照以下方式进行自定义:
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.foo]
address = ":8080"
[entryPoints.bar]
address = ":8081"
# 激活 API 和仪表板
[api]
entryPoint = "bar"
dashboard = true
[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的相关文档可以在这里找到。
<details>
<summary>英文:</summary>
You can customize it as below
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.foo]
address = ":8080"
[entryPoints.bar]
address = ":8081"
# Activate API and Dashboard
[api]
entryPoint = "bar"
dashboard = true
[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"
Corresponding docs from Traefik [here][1]
[1]: https://docs.traefik.io/v1.7/configuration/api/#custom-path
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论