How to enable Google Cloud kubernetes CORS?

I’m serving my static pages from Firebase.
I have an API service running on GKE cloud.

Both of the services under the same domain (example.com and api.example.com),
and use the same protocol (https).

When I try to access the api.example.com I get access-control-allow-origin rejection.
How can I configure GKE to enable CORS from the same domain?

If you want to enable CORS at the ingress level you can do so within the spec using annotations.

If you are referring only to firebase (though I don’t see the relation to GKE) then you need to tell your express app to use CORS:

app.use((req, res, next) => {

    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.setHeader('Access-control-Allow-Headers', 'Content-Type,Authorization');

    next();

});
2 Likes

Hi,
I’m having a similar issue on GKE (but without using firebase). The answer here seems to provide a config for Ingress (whatever that is)… but it doesn’t explain what Ingress is nor whether it’s something that needs to be installed or if it comes standard with a gcloud kubernetes cluster or what? Also it doesn’t tell us what the yaml file shown is nor what to do with it… is it a Deployment yaml definition file?

Also is there no way to enable CORS without Ingress?