Can't setting CORS Traefik V2

I'm trying to raise the version of Traefik I'm building on Kubernetes from v1 to v2.

I was able to update itself, but when I try to use the application after updating the Traefik version to v2, I get a CORS error.

I checked the documentation and found that CORS can be configured in the middleware configuration, so I configured it as follows.

trying to access https://backend.example.com from https://front.example.com

[http.middlewares]
  [http.middlewares.testHeader.headers]
    accessControlAllowMethods= ["GET", "OPTIONS", "PUT", "POST", "DELETE"]
    accessControlAllowOriginList = ["https://*.example.com"]
    accessControlMaxAge = 100
    addVaryHeader = true
  • ingress setting
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: example-app
  labels:
    app.kubernetes.io/name: example-app
  annotations:
    ingress.kubernetes.io/whitelist-x-forwarded-for: "true"
    ingress.kubernetes.io/protocol: https
    traefik.ingress.kubernetes.io/router.tls: "true"
    kubernetes.io/ingress.class: traefik
spec:
  rules:
    - host: backend.example.com
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              serviceName: example-app
              servicePort: 443

but this problem not sloved.

When I checked the error, I found that the preflight had failed.

has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I would like to know if there is any part of the problem and if there are any other settings that need to be made.

Thank you.

Loading the configured middleware solves the preflight problem, but the CORS problem is still there.

Hi there @yuzujoe, I think the plugin traefik-plugin-cors might be able to help you :slight_smile:
See the pilot's plugin page.

1 Like