<p>I've done this previously in python using:</p>

<pre><code>    with open(path.join(path.dirname(__file__), "job.yaml")) as f:
        body= yaml.safe_load(f)

        try:
            api_response = api_instance.create_namespaced_job(namespace, body)
</code></pre>

<p>Looking at source of the nodejs api client:</p>

<pre><code>    public createNamespacedJob (namespace: string, body: V1Job, includeUninitialized?: boolean, pretty?: string, dryRun?: string, options: any = {}) : Promise&lt;{ response: http.IncomingMessage; body: V1Job;  }&gt; {
</code></pre>

<p>How can I generate that the <code>V1Job</code>?</p>

<hr>

<p>I've tried the below but get back a very verbose error message / response:</p>

<pre><code>const k8s = require('@kubernetes/client-node');
const yaml = require('js-yaml');
const fs   = require('fs');

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

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

var namespace = {
    metadata: {
        name: 'test123',
    },
};

try {
    var job = yaml.safeLoad(fs.readFileSync('job.yaml', 'utf8'));

    k8sApi.createNamespacedJob(namespace, job).then(
        (response) =&gt; {
            console.log('Created namespace');
            console.log("Success!")
        },
        (err) =&gt; {
            console.log(err);
            console.log(job);
            console.log("Err")
        },
    );

} catch (e) {
    console.log(e);
}
</code></pre>

Chris Stryczynski
<ol>
<li><code>V1Job</code> seems to be an ordinary object so the below worked. </li>
<li>Namespace had to be a <code>string</code> rather than an object...</li>
</ol>

<pre><code>const k8s = require('@kubernetes/client-node');
const yaml = require('js-yaml');
const fs   = require('fs');

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

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

try {
    var job = yaml.safeLoad(fs.readFileSync('job.yaml', 'utf8'));

    k8sApi.createNamespacedJob("default", job).then(
        (response) =&gt; {
            console.log("Success")
        },
        (err) =&gt; {
            console.log(e);
            process.exit(1);
        },
    );

} catch (e) {
    console.log(e);
    process.exit(1);
}
</code></pre>
