I have kubernetes cluster on my GCP platform and I want to get Node's list in my cluster by using client-node lib.
const cluster = {
name: 'my-cluster-1',
server: 'https://endpoints.googleapis.com',
};
const user = {
name: 'myemail@gmail.com',
password: 'mypassword',
};
const kc = new k8s.KubeConfig();
kc.loadFromClusterAndUser(cluster, user);
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
k8sApi.listNode()
.then((res) => {
console.log('RESULT: ' + JSON.stringify(res));
})
.catch((err) => {
console.log('ERROR: ' + err);
});
But this code fails with Bad Gateway
message.
Kubernetes client lib expects the Kubernetes user credentials which are not the same as the Gmail/Gsuite credentials.
Get the user credentials for cluster using gcloud container clusters get-credentials [CLUSTER_NAME]
and then load the config as below
const kc = new k8s.KubeConfig();
kc.loadFromDefault();