<p>I have a shell script that has several kubectl commands, I need to execute it as a part of helm installation.</p>

<p><code>#!/bin/bash
kubectl create secret generic mysecret --from-literal=username=$USER_NAME --from-literal=password=$passwrd</code></p>

<p>I have written a job which execute this script.</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: "sagdfghd"

spec:
  template:        
    spec:
      containers:
        - name: sagdfghd
          image: {{ .Values.jobs.dockerRegistry }}
          command: ["sh", "-c", {{ .Files.Get "scripts/myscript.sh" | quote }} ]
</code></pre>

<p>But as the script is running inside container it is not able to find kubectl command.</p>

<p>Any idea how can I run this script??</p>

<p>TIA</p>

Sudhir Pandey
<p>@ericstaples provided <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl" rel="nofollow noreferrer">link to installation documentation</a> and it help to resolve issue:</p>

<blockquote>
  <p>What image does {{ .Values.jobs.dockerRegistry }} resolve to and does
  it have the kubectl tool installed on it?</p>
</blockquote>

<p>It most likely does not have kubectl installed on it, so you will have to add the kubectl install instructions in your Dockerfile. Those instructions will depend on what your base Docker image is.</p>

<p>Since the Pod created by the Job will have a ServiceAccount attached to it, the kubectl tool running in the container will make calls to the cluster in which it's running via the ServiceAccount token, and will in fact create the Secret in the cluster, not the container (assuming it has the correct RBAC permissions). </p>

<p>Try it out. Making calls to the kube-apiserver (e.g. via kubectl) from containers is not uncommon. </p>

<p>Side note: creating a Secret object in a container makes absolutely no sense. </p>
