Traefik仪表板 – 自定义API路径

huangapple go评论55阅读模式
英文:

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: &quot;2&quot;
spec:
  rules:
  - http:
      paths:
      - path: /dashboard
        backend:
          serviceName: traefik-web-ui
          servicePort: http
      - path: /api &lt;-- needed to make dashboard&#39;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: &quot;999&quot;
spec:
  rules:
  - http:
      paths:
      - path: /apis/ &lt;-- i&#39;d rather use /api here
        backend:
          serviceName: {{ include &quot;my-backend.fullname&quot; . }}
          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 = [&quot;http&quot;]
    
    [entryPoints]
      [entryPoints.http]
      address = &quot;:80&quot;
    
      [entryPoints.foo]
      address = &quot;:8080&quot;
    
      [entryPoints.bar]
      address = &quot;:8081&quot;
    
    # Activate API and Dashboard
    [api]
    entryPoint = &quot;bar&quot;
    dashboard = true
    
    
      [backends]
        [backends.backend1]
          [backends.backend1.servers.server1]
          url = &quot;http://127.0.0.1:8081&quot;
    
      [frontends]
        [frontends.frontend1]
        entryPoints = [&quot;foo&quot;]
        backend = &quot;backend1&quot;
          [frontends.frontend1.routes.test_1]
          rule = &quot;PathPrefixStrip:/yourprefix;PathPrefix:/yourprefix&quot;


Corresponding docs from Traefik [here][1]


  [1]: https://docs.traefik.io/v1.7/configuration/api/#custom-path

</details>



huangapple
  • 本文由 发表于 2020年1月3日 16:51:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59575542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定