Configure a middleware for all IngressRoutes

I have a IngressRoute + CORS Middleware like that ...

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: my-route
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - kind: Rule
      match: 'PathPrefix(`/my-path`)'
      middlewares:
        - name: cors-allowed
      services:
        - name: my-service
          port: http
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: cors-allowed
  namespace: default
spec:
  headers:
    accessControlAllowHeaders:
      - '*'
    accessControlAllowMethods:
      - '*'
    accessControlAllowOriginList:
      - '*'
    accessControlMaxAge: 100
    addVaryHeader: true

Is it possible to link the middleware without declare the middleware.name: cors-allowed?
Or others
Is it possible to configure a global middleware for every IngressRoute?

Thanks for any hint.

Jan

Hi @jwausle ,
I have created several Middleware resources and bundled them with a chain middleware. The chain middleware is added to an entrypoint via a command line argument (e.g. --entrypoints.web-secure.http.middlewares=${NAMESPACE}-default-chain@kubernetescrd). Any IngressRoute that uses this entrypoint will automatically use the middleware resources as well.

Great idea Bernhard,

  • I found the doc
  • I will check it out and send response.

Thanks and happy new year 2022

1 Like