<p>I am working on building a project using Node.js which will require me to have an application that can deploy to Kubernetes. The service I am working on will take some Kubernetes manifests, add some ENV variables into them, and then would deploy those resources.</p>
<p>I have some code that can create and destroy a namespace for me using the SDK and <code>createNamespace</code> and <code>deleteNamespace</code>. This part works how I want it to, ie without needing a Kubernetes YAML file. I would like to use the SDK for creating a deployment as well however I can't seem to get it to work. I found a code example of <code>createNamespacedDeployment</code> however using version <code>0.13.2</code> of the SDK I am unable to get that working. I get this error message when I run the example code I found.</p>
<pre><code>k8sApi.createNamespacedDeployment is not a function
</code></pre>
<p>I have tried to check over the git repo for the SDK though it is massive and I've yet to find anything in it that would allow me to define a deployment in my Node.js code, closest I have found is a pod deployment however that won't work for me, I need a deployment.</p>
<p>How can I create a deployment via Node.js and have it apply to my Kubernetes cluster?</p>

joshk132
<p>Management of deployments is handled by the <a href="https://kubernetes-client.github.io/javascript/classes/appsv1api.appsv1api-1.html" rel="nofollow noreferrer">AppsV1Api</a> class:</p>
<pre><code>const k8s = require('@kubernetes/client-node');

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

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

const deploymentYamlString = fs.readFileSync('./deployment.yaml', { encoding: 'utf8'});
const deployment = k8s.loadYaml(deploymentYamlString);
const res = await appsApi.createNamespacedDeployment('default', deployment);
</code></pre>
<p>Generally, you can find the relevant API class for managing a Kubernetes object by its apiVersion, eg: Deployment -&gt; <code>apiVersion: apps/v1</code> -&gt; <code>AppsV1Api</code>, CronJob -&gt; <code>apiVersion: batch/v1</code> -&gt; <code>BatchV1Api</code>.</p>
