<p>I am running app in k8s.</p>
<p>Lets say is some web app with admin administration.</p>
<p>In this admin addministration is magic button to run some task.</p>
<p>This task should be started as k8s job.</p>
<p>My question is:</p>
<p>How to start correctly k8s job from this administration backend app.</p>
<p>Should I install <code>kubectl</code> into administration app docker image, and just run some <code>kubectl apply</code> from my backend app?</p>
<p>Like:</p>
<pre><code>// when server receive http
onStart(req, resp) =&gt; {
  const { spawn } = require('child_process');
  const ls = spawn('kubectl', ['apply', '-f', 'path-to-job-config.yaml']);
}
</code></pre>
<ul>
<li>in my case I am using nodejs, but I think its verry bad share some k8s configs/credentials in app docker images.</li>
</ul>
<p>How to solve this problem?</p>

bamamey612
<p>You can use the <a href="https://github.com/Goyoo/node-k8s-client" rel="nofollow noreferrer">nodejs client library</a> to create a Job by calling kubernetes REST API.</p>
<p>Or you could use an http client library to call the same REST API.</p>
<p>For authentication use a service account token which is a JWT bearer token and can be sent as part of <code>Authorization</code> header. The service account needs to be <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/" rel="nofollow noreferrer">RBAC</a> authorization permission to create a Job.</p>
