Enabling CORS in Kubernetes API server with HTTPS

6/28/2016

I'm trying to work with Kubernetes API server from Angular JS front-end app. The API server uses https endpoint. The front-end app is deployed to the other server.

Despite the --cors-allowed-origins=.* (or --cors-allowed-origins=["http://*"]) param for kube-apiserver I can't access API because when I try to make GET XHR request, pre-flight OPTIONS request failed with 401 response without CORS headers.

However, when I switch from https to http, everything works fine.

Looks like I'm facing this issue, which is already fixed and merged in the version of Kubernetes I'm using.

Versions are Kubernetes 1.2.4, Angular JS 1.5.4 and Chrome 51.

Could you tell me why it happens and how to fix this? I need a working solution for https.

-- dds
angularjs
kubernetes
xmlhttprequest

2 Answers

4/23/2019

You can edit kubernetes API server yaml file, to get CORS working.

Location: /etc/kubernetes/manifests/kube-apiserver.yaml

Add - --cors-allowed-origins=http://www.example.com,https://*.example.com this line under kube-apiserver

spec:
containers:
- command:
  - kube-apiserver
  - --cors-allowed-origins=http://www.example.com,https://*.example.com

Coma separated domains or regular expressions you can add.

No need to restart kube-apiserver, once file saved kube-apiserver will automatically restart.

it will take 5 to 10min time to get API server up.

-- Malaji Nagaraju
Source: StackOverflow

6/28/2016

The issue you linked to was fixed, but a regression in CORS handling was introduced by kubernetes/kubernetes#18113 and has yet to be fixed (see kubernetes/kubernetes#24086). It is currently marked as a known issue for the imminent 1.3 release, which means that it is an outstanding bug.

-- Robert Bailey
Source: StackOverflow