Higor Ramos
Higor Ramos

Reputation: 475

how to enable-cors in GKE with ingress

I'm trying to enable cors with ingress without success using the following annotation:

 kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/enable-cors: "true"

Upvotes: 4

Views: 8640

Answers (2)

user8709030
user8709030

Reputation:

This is a supplement to the approved answer for people using Kubernetes on GCP.

If people having an existing ingress running with class gce, they need to switch over to nginx first.

Then you should follow the installation steps at NGINX Ingress Controller - Installation Guide.

But please note, if you are using Kubernetes 1.8+, you have RBAC enabled by default. This might give you an error while running the first RBAC installation line. The error is like: "Error from server (Forbidden): error when creating "STDIN": clusterroles.rbac.authorization.k8s.io "nginx-ingress-clusterrole" is forbidden: attempt to grant extra privileges".

While having this configuration step failed, the nginx ingress controller won't run, it will crash over and over again complaining about RBAC.

When I did a search on the net myself, I found a post related to this error and it helped me to get a running nginx ingress controller.

Please read the post by user dafstone at March 5 2018.

It adds your GCP account as a cluster admin which allows you to install the required RBAC rules as explained in the installation guide at first.

Good luck!

Upvotes: 1

Lev Kuznetsov
Lev Kuznetsov

Reputation: 3728

The correct annotation is ingress.kubernetes.io/enable-cors: "true"

Upvotes: 4

Related Questions