【问题标题】:Traefik v2 Middlewares not being detected未检测到 Traefik v2 中间件
【发布时间】:2020-02-27 10:30:46
【问题描述】:

未检测到中间件,因此未剥离路径,导致后端 api 出现 404。

中间件存在于 k8s 应用命名空间中

$ kubectl get -n apps middlewares
NAME                                                AGE
traefik-middlewares-backend-users-service           1d

中间件和入口路由的配置

---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
  name: apps-services
  namespace: apps
spec:
  entryPoints:
    - web
  routes:
    - kind: Rule
      match: Host(`example.com`) && PathPrefix(`/users/`)
      middlewares:
        - name: traefik-middlewares-backend-users-service
      priority: 0
      services:
        - name: backend-users-service
          port: 8080
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: traefik-middlewares-backend-users-service
  namespace: apps
spec:
  stripPrefix:
    prefixes:
      - /users

静态配置

global:
  checkNewVersion: true
  sendAnonymousUsage: true
entryPoints:
  http:
    address: :80
  traefik:
    address: :8080
providers:
  providersThrottleDuration: 2s
  kubernetesIngress: {}
api:
  # TODO: make this secure later
  insecure: true
ping:
  entryPoint: http
log: {}

Traefik 仪表板没有中间件

Spring Boot 404 页面。路线在 example.com/actuator/health

/users 未被剥离。这在 traefik v1 中非常适合我。

注意:示例中的实际域已替换为example.comdomain.com

【问题讨论】:

    标签: traefik traefik-ingress


    【解决方案1】:

    为了让这个工作,我必须:

    1. 使用 traefik v2 的自定义 k8s CRD 所在的命名空间添加 Kubernetes CRD 提供程序
    2. 添加 TLSOption 资源定义
    3. 更新 traefik 的集群角色以拥有列出和观看新 v2 资源的权限
    4. 确保所有具有新资源的命名空间都已配置

    Traefik 静态配置文件

    providers:
      providersThrottleDuration: 2s
      kubernetesCRD:
        namespaces:
          - apps
          - traefik
    

    TLSOption CRD

    ---
    apiVersion: apiextensions.k8s.io/v1beta1
    kind: CustomResourceDefinition
    metadata:
      name: tlsoptions.traefik.containo.us
    spec:
      group: traefik.containo.us
      version: v1alpha1
      names:
        kind: TLSOption
        plural: tlsoptions
        singular: tlsoption
      scope: Namespaced
    

    更新了 Traefik 的静态配置

    global:
      checkNewVersion: true
      sendAnonymousUsage: true
    entryPoints:
      http:
        address: :80
      traefik:
        address: :8080
    providers:
      providersThrottleDuration: 2s
      kubernetesCRD:
        namespaces:
          - apps
          - traefik
    api:
      # TODO: make this secure later
      insecure: true
    ping:
      entryPoint: http
    log: {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 2020-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      相关资源
      最近更新 更多