<p>I am using <code>@kubernetes/client-node</code> to access Kubernetes server API. I can get all the Pods from default using:</p>
<pre><code>const k8s = require('@kubernetes/client-node');

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

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

k8sApi.listNamespace().then((res) =&gt; {  // or using listAllNamespacedPods
    console.log(res.body);
});
</code></pre>
<p>and the body of the response from the above code looks like this:</p>
<p><a href="https://i.stack.imgur.com/wV30C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wV30C.png" alt="Response From loadFromDefault" /></a></p>
<p>but when I am using <code>kc.loadFromFile('pathToKubeConfigFile')</code>, it is unable to read it (the <code>config.yaml</code> which is saved inside <code>.kube</code> folder).
I have checked all the paths to certificates and keys files inside this file and they are correct.</p>
<pre><code>import { KubeConfig, CoreV1Api } from '@kubernetes/client-node';

const kc = new KubeConfig();
kc.loadFromFile('./config/k8sConfig.yaml');

const k8sApi = kc.makeApiClient(CoreV1Api);

k8sApi.listPodForAllNamespaces().then((res) =&gt; {
    console.log(res.body);
});
</code></pre>
<p>and I need to return all the active Kubernetes Jobs (or the pods for that). Can anyone please suggest me how to achieve it?</p>

shivam
<p>As the problem has already been resolved in the comments section, I decided to provide a Community Wiki answer just for better visibility to other community members. I would also like to describe how to return all active Kubernetes Jobs using the <a href="https://github.com/kubernetes-client/javascript#javascript-kubernetes-client-information" rel="nofollow noreferrer">Javascript Kubernetes Client</a></p>
<h5>Using the loadFromFile() method.</h5>
<p>When using the <code>loadFromFile()</code> method, it's important to make sure that the <code>kubeconfig</code> file is correct. In case the <code>kubeconfig</code> file is invalid, we may get various error messages such as:</p>
<pre><code>Error: ENOENT: no such file or directory, open '.kube/confi'
</code></pre>
<p>or</p>
<pre><code>Error: unable to verify the first certificate
</code></pre>
<p>The exact error message depends on what is incorrect in the <code>kubeconfig</code> file.</p>
<h5>List all/active Kubernetes Jobs.</h5>
<p>To list all Kubernetes Jobs, we can use the <a href="https://github.com/kubernetes-client/javascript/blob/1d5d4660f99807e3d3b02dd0984d0b980f279ff9/src/gen/api/batchV1Api.ts#L950" rel="nofollow noreferrer">listJobForAllNamespaces()</a> method.</p>
<p>I've created the <code>listAllJobs.js</code> script to demonstrate how it works:</p>
<pre><code>$ cat listAllJobs.js
const k8s = require('@kubernetes/client-node')
const kc = new k8s.KubeConfig()
kc.loadFromFile('.kube/config')

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

k8sApi.listJobForAllNamespaces().then((res) =&gt; {
    res.body.items.forEach(job =&gt; console.log(job.metadata.name));
});


$ kubectl get jobs
NAME    COMPLETIONS   DURATION   AGE
job-1   0/1           3s         3s
job-2   1/1           10s        48m
job-3   1/1           10s        48m 

$ node listAllJobs.js
job-1
job-2
job-3
</code></pre>
<p>To list only active Jobs, we need to slightly modify the <code>res.body.items.forEach(job =&gt; console.log(job.metadata.name));</code> line to check if the Job is active:</p>
<pre><code>$ cat listActiveJobs.js
const k8s = require('@kubernetes/client-node')
const kc = new k8s.KubeConfig()
kc.loadFromFile('.kube/config')

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

k8sApi.listJobForAllNamespaces().then((res) =&gt; {
    res.body.items.forEach(job =&gt; job.status.active &gt;= 1 &amp;&amp; console.log(job.metadata.name));
});


$ kubectl get jobs
NAME    COMPLETIONS   
job-1   0/1           
job-2   1/1           
job-3   1/1          

$ node listActiveJobs.js 
job-1
</code></pre>
