<p>I am trying to enable CORS on ingress in kubernetes running traefik. So that in the response header I could add CORS origin to be allowed to every host for now.
How can I do that?
Below is the k8 ingress.yml file.</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  namespace: test
  labels:
    app: test-cors-app
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: company.host
    http:
      paths:
      - path: /
        backend:
          serviceName: test-service
          servicePort: 80
</code></pre>
<p><strong>UPDATE</strong> I have traefik 1.7</p>

<p>You can use this annotation in your ingress : <code>traefik.ingress.kubernetes.io/custom-response-headers</code> or <code>ingress.kubernetes.io/custom-response-headers</code> both will work with traefik.</p>
<p>Modify your ingress.yml file as :</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  namespace: test
  labels:
    app: test-cors-app
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/custom-response-headers: &quot;Access-Control-Allow-Origin:*||Access-Control-Allow-Methods:GET,POST,OPTIONS||Access-Control-Allow-Headers:DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range||Access-Control-Expose-Headers:Content-Length,Content-Range&quot;
spec:
  rules:
  - host: company.host
    http:
      paths:
      - path: /
        backend:
          serviceName: test-service
          servicePort: 80
</code></pre>
<p>**Modify annotation attributes accrodingly. It works for traefik lower versions as well. see <a href="https://doc.traefik.io/traefik/v1.7/configuration/backends/kubernetes/" rel="nofollow noreferrer">here</a></p>
