'Kubernetes Javascript Client Library works on local but not on GKE

I'm trying to use the Kubernetes JS client library, and when i try it on a local environment (i am using docker to run a local kubernetes) it works fine, i am creating a pod for testing purposes and the pod is created. When i try on Google Kubernetes Engine i get "HttpError: HTTP request failed".

Here is how i am using the library:

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);


Then i use the following method to create a pod, using a V1Pod body:

k8sApi.createNamespacedPod("default", pod).then(
    (response) => {
        console.log(`Created pod -> ${response}`);
    },
    (err) => {
        console.log(`Error: ${err}`);
    }
);


Solution 1:[1]

I'm not sure if you resolved this but I got additional information by using JSON.stringify(e) on the error generated by the creation function (i.e, api.createNamespacedCronJob(...)). If you look at the github repository for the k8s javascript client the HttpError object contains a response, body and status code. That was very helpful in my case. It was a 403 forbidden due to the perms of the service account being used for the request.

Kubernetes Javascript Client HttpError (produces that message): https://github.com/kubernetes-client/javascript/blob/ab5fc88afb4a205b1686078feca7e233f610c4f6/src/gen/api/apis.ts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1