未检测到Traefik v2中间件

时间:2019-11-01 03:56:11

标签: traefik traefik-ingress

未检测到中间件,因此未剥离路径,从而导致后端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 dasboard没有中间件

traefik v2 dashboard

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

/users未被剥离。这对我来说在traefik v1中非常有效。

注意:示例中的实际域已被example.comdomain.com取代。

spring boot 404 page

1 个答案:

答案 0 :(得分:0)

要使其正常工作,我必须:

  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: {}