Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
like image 791
Higor Ramos Avatar asked Oct 26 '25 11:10

Higor Ramos


2 Answers

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

like image 135
Lev Kuznetsov Avatar answered Oct 28 '25 02:10

Lev Kuznetsov


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!


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!