title: Dynamic Command for Kubernetes Jobs
body: <p>So hopefully this makes sense to the non-Djangoers of the k8s community. I will try my best to explain the setup / reasoning.</p>
  <p>With Django, we have LOTS of what are called management commands that we can run within the scope and environment of our Django app that can really help development and deployment. I'm sure most other frameworks have similar, if not identical, concepts.</p>
  <p>An example would be the &quot;<code>python manage.py migrate</code>&quot; command that ensures our codebase (migration scripts) are applied to and reflect in the associated database.</p>
  <p>There are approx. 30 - 50 core commands we can run, we can also create our own, as well as apply those from any installed third party applications.</p>
  <p>Anyways. The most important takeaway is that there are a lot of commands we can and do run.</p>
  <p>Now, I have the following k8s Job to run the &quot;migrate&quot; command:</p>
  <pre><code>apiVersion: batch/v1
  kind: Job
  metadata:
    name: asencis-web-migrate-job
  spec:
    template:
      spec:
        containers:
          - name: asencis-web-migrate-job
            image: asencis/asencis-base:latest
            imagePullPolicy: Always
            command: ['python', 'manage.py', 'migrate']
            envFrom:
            - configMapRef:
                name: asencis-config
            - secretRef:
                name: asencis-secret
        restartPolicy: Never
    backoffLimit: 5
  </code></pre>
  <p>This job essentially runs the <code>python manage.py migrate</code> command within the application scope/environment. It works like a charm:</p>
  <pre class="lang-sh prettyprint-override"><code>$ kubectl apply -f asencis-web-migrate-job.yaml
  </code></pre>
  <p>It's very useful in the deployment of the application when all of our tests have run, we can then build an image, &quot;rollout restart&quot; the cluster and then apply any migrations. It's incredibly seamless. (Not of my hat to the k8s core team for making such a useful product!)</p>
  <p>Anyways.</p>
  <p>My question is essentially this, <em><strong>can we apply an argument to the above <code>kubectl apply</code> command on the job, to run any command we like</strong></em>?</p>
  <p>An example would be:</p>
  <pre class="lang-sh prettyprint-override"><code>$ kubectl apply -f asencis-web-job.yaml --command python manage.py migrate
  </code></pre>