Traefik 2.2.5 CORS middleware does not exist error

I am trying to setup the traefik with cors using the latest github from: containous/traefik-helm-chart

  • I have left most by default and using these providers:
providers:
  kubernetesCRD:
    enabled: true
  kubernetesIngress:
    enabled: true

I have installed all the crds and then installed a cors middleware in a traefik namespace:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: cors-header
spec:
  headers:
    accessControlAllowMethods:
      - "GET"
      - "OPTIONS"
      - "PUT"
    accessControlAllowOriginList:
      - "*"
    accessControlMaxAge: 100
    addVaryHeader: true

I also installed an the ingress:

kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
  name: myingress
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web
    traefik.ingress.kubernetes.io/router.middlewares: corsheader@kubernetescrd

spec:
  rules:
    - host: *
      http:
        paths:
          - path: /v1
            backend:
              serviceName: test-service
              servicePort: 8080
I am getting these errors on the pod logs:
time="2020-07-28T23:17:09Z" level=error msg="middleware \"corsheader@kubernetesingress\" does not exist" entryPointName=web routerName=myingress-traefik-fit-v2@kubernetes
time="2020-07-28T23:17:09Z" level=error msg="middleware \"corsheader@kubernetesingress\" does not exist" entryPointName=web routerName=myingress-traefik-fit-v1@kubernetes
time="2020-07-28T23:31:50Z" level=error msg="middleware \"cors-header@kubernetescrd\" does not exist" routerName=myingress-traefik-fit-v2@kubernetes entryPointName=web
time="2020-07-28T23:31:50Z" level=error msg="middleware \"cors-header@kubernetescrd\" does not exist" entryPointName=web routerName=myingress-traefik-fit-v1@kubernetes
time="2020-07-28T23:53:40Z" level=error msg="middleware \"cors-header@kubernetes\" does not exist" routerName=myingress-traefik-fit-v2@kubernetes entryPointName=web
time="2020-07-28T23:53:40Z" level=error msg="middleware \"cors-header@kubernetes\" does not exist" entryPointName=web routerName=myingress-traefik-fit-v1@kubernetes

I tried traefik.ingress.kubernetes.io/router.middlewares: cors-header@kubernetescrd
and traefik.ingress.kubernetes.io/router.middlewares: cors-header@kubernetesingress
and traefik.ingress.kubernetes.io/router.middlewares: cors-header but still errors

Please kindly assist.

Thank you

this issue has been solved and can be closed.

1 Like

What did you do to fix it?

1 Like

that helped me solve it by adding the namespace prefix

This link is absolutely correct - thank you so much. In the Ingress annotations - instead of putting:- traefik.ingress.kubernetes.io/router.middlewares: "billing/cors-headers@kubernetescrd", where 'billing' is the namespace and 'cors-headers' is the name of the middleware, I changed to: traefik.ingress.kubernetes.io/router.middlewares: "billing-cors-headers@kubernetescrd" - so a dash instead of a slash. I assume that the middleware reference does not expect a namespace, but rather integrates the namespace into the middleware name directly but utterly show-stopping, badly documented and time costly to pin down.