# How to enable CORS plugin on K8S and dbless kong

**URL:** https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151
**Category:** Questions
**Tags:** kubernetes
**Created:** [December 13, 2019, 7:35pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151 "2019-12-13T19:35:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![arvtiwar](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@arvtiwar](https://discuss.konghq.com/u/arvtiwar)
#### Post date: [December 13, 2019, 7:35pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/1 "2019-12-13T19:35:51Z")

</div>

I have to enable CORS plugin on K8S and dbless kong.  
Any example available?

Thanks in advance

---

<div class="post-metadata">

### Author: ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)
#### Post date: [December 16, 2019, 5:48pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/2 "2019-12-16T17:48:40Z")

</div>

@arvtiwar Please do not cross-post. It leaves threads hanging in the forum and the maintainers have a hard time navigating all the notifications. If you post once, please have patience and someone will get back to you as soon as they can.

Regarding this:

> [@Looking for examples and doc reference](https://discuss.konghq.com/t/looking-for-examples-and-doc-reference/5132/7):
>
> does this plug cong looks good? apiVersion: [configuration.konghq.com/v1](http://configuration.konghq.com/v1) kind: KongPlugin metadata: name: http-cors namespace: app-dev plugin: cors config: origins: “[https://my.origin.net](https://my.origin.net)” methods: GET POST PUT DELETE PATCH OPTIONS headers: Accept Accept-Version Content-Length Content-MD5 Content-Type Date X-Auth-Token exposed\_headers: X-Auth-Token credentials: true max\_age: 3600

What problem did you run into? That looks correct on the face of it.  
The general guidelines is that you should take the `config` part of the plugin configuration from the docs site and then change it to YAM format under the config property of KongPlugin resource.

---

<div class="post-metadata">

### Author: ![arvtiwar](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@arvtiwar](https://discuss.konghq.com/u/arvtiwar)
#### Post date: [December 16, 2019, 6:15pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/3 "2019-12-16T18:15:27Z")

</div>

Sorry for cross-post.  
This is how I set up the plugin and ingress

> <https://gist.github.com/arvtiwar/255aefce16ed07427e50ec694d7d70b4>

  
My problem is, it is not at all setting up the CORS headers as defined in config.  
Thanks  
Arvind

---

<div class="post-metadata">

### Author: ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)
#### Post date: [December 17, 2019, 6:03pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/4 "2019-12-17T18:03:51Z")

</div>

> [@arvtiwar](#):
>
> My problem is, it is not at all setting up the CORS headers as defined in config.

Can you login into the Kong container and check if the plugin has the right configuration ?  
You can use Kong’s Admin API to check that.

---

<div class="post-metadata">

### Author: ![arvtiwar](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@arvtiwar](https://discuss.konghq.com/u/arvtiwar)
#### Post date: [December 17, 2019, 9:33pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/5 "2019-12-17T21:33:54Z")

</div>

FYI, this Kong community edition. I guess kong-admin is not for community edition?  
More info  
This K8S 1.16.2 instance on DigitalOcen  
I have two service {myapp-web, myapp-api} running which kong is proxing.

> <https://gist.github.com/arvtiwar/3ad714f7467071a17222dadc6b0a09ff>

Observation 1  
If remove ([configuration.konghq.com](http://configuration.konghq.com): myapp-kong-ingress) below which enforces HTTPS and access “[http://devui.myapp.net](http://devui.myapp.net)” on HTTP all CORS headers are set and all works fine

Observation 2  
When I enable ([configuration.konghq.com](http://configuration.konghq.com): myapp-kong-ingress) and access “[https://devui.myapp.net](https://devui.myapp.net)” on HTTPS, CORS plugin is not working as no header on API response

Observation 3  
Directly hitting the API after enabling “http-add-header”, no header is there as we are setting up “Access-Control-Allow-Origin: [https://devui.myapp.net](https://devui.myapp.net)” on the plugin

Any idea?

Also when you say “login into the Kong container” you mean using the shell? are we running shell in “kong-proxy” container? More context please

Thanks

---

<div class="post-metadata">

### Author: ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)
#### Post date: [December 18, 2019, 5:20pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/6 "2019-12-18T17:20:51Z")

</div>

> [@arvtiwar](#):
>
> Also when you say “login into the Kong container” you mean using the shell? are we running shell in “kong-proxy” container? More context please

shell into the kong-proxy container and look up the Admin API.

---

<div class="post-metadata">

### Author: ![arvtiwar](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@arvtiwar](https://discuss.konghq.com/u/arvtiwar)
#### Post date: [December 18, 2019, 6:28pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/7 "2019-12-18T18:28:16Z")

</div>

Thanks Harry for all the suggestions. let me try

---

<div class="post-metadata">

### Author: ![esatterwhite](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/esatterwhite/32/2871_2.png) [@esatterwhite](https://discuss.konghq.com/u/esatterwhite)
#### Post date: [September 12, 2021, 6:13pm UTC](https://discuss.konghq.com/t/how-to-enable-cors-plugin-on-k8s-and-dbless-kong/5151/8 "2021-09-12T18:13:24Z")

</div>

I’m noticing this behavior as well.  
mainly `Access-Control-Allow-Headers` and `Access-Control-Allow-Methods`

```auto
Name: cors
Namespace: default
Labels: <none>
Annotations: <none>
API Version: configuration.konghq.com/v1
Config:
  Credentials: true
  exposed_headers:
    Authorization
  Headers:
    Accept
    Accept-Version
    Content-Length
    Content-MD5
    Content-Type
    Date
    X-Requested-With
  max_age: 3600
  Methods:
    GET
    POST
    PUT
    DELETE
    OPTIONS
  Origins:
    *
  preflight_continue: false
Kind: KongPlugin
Metadata:
  Creation Timestamp: 2021-09-12T18:08:28Z
  Generation: 1
  Managed Fields:
    API Version: configuration.konghq.com/v1
    Fields Type: FieldsV1
    fieldsV1:
      f:config:
        .:
        f:credentials:
        f:exposed_headers:
        f:headers:
        f:max_age:
        f:methods:
        f:origins:
        f:preflight_continue:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
      f:plugin:
    Manager: Go-http-client
    Operation: Update
    Time: 2021-09-12T18:08:28Z
  Resource Version: 14686
  UID: b8669971-67bc-4916-a964-c0b70e639d4c
Plugin: cors
Events: <none>

```
