I am writing a script that will create secrets in Kubernetes without putting the base64 encoded files in plain text anywhere but etcd. To do this I'm talking to kubernetes' api server directly and not through kubectl. When I make a request, it requires a namespace, which makes sense.
However, the response I receive about the namespace is "the namespace of the provided object does not match the namespace sent on the request". I looked into both the api server and kubectl's source code to see if there's something special that kubectl does that I'm not doing that would cause this issue. What would be the reason I am getting this error? Am I missing headers or a cookie or something like that?
This is my request (I'm writing in JS):
var data = JSON.stringify(/* Secret spec */);
var req = http.request({
hostname: argObj.host ? argObj.host : '127.0.0.1',
port: argObj.port ? argObj.port : '8080',
path: '/api/v1/secrets',
method: argObj.method ? argObj.method : 'POST',
headers: {
'Content-Type': 'application/json'
}
}, (res)=>{/* handle res */});
req.write(data);
I've left out my authentication on purpose in this example, I can confirm I am auth'd.
So the solution is to POST to "/api/v1/namespaces/{namespace}/secrets" instead