k8s node get services for a namespace

11/6/2020

I need to get the list of k8s services for some namespace, I need to run it in my local machine which is connected to k8s cluster . e.g. if I run kubectl get ns on my machine(macbook) I get the list for namespaces and the same for services using kubectl get svc -n abc

My kubeconfig is defined under my mac /Users/i453335/.kube/config file

When I try to run the following code, I got error

Error: unable to get issuer certificate (not sure how to provide it and from where) or maybe I need to to use loadFromDefault differently ...

Any idea how I could make it work?

const k8s = require('@kubernetes/client-node');

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

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

k8sApi.listNamespacedService('abc').then((res) => {
    console.log(res.body);
});

This is the lib I use: https://github.com/kubernetes-client/javascript

-- NSS
certificate
javascript
kubernetes
node.js

0 Answers