<p>I've found 2 different ways to run a one-off command in my kubernetes cluster:</p>

<h2>Method 1</h2>

<pre><code>kubectl apply -f kubernetes/migrate.job.yaml
kubectl wait --for=condition=complete --timeout=600s job/migrate-job
kubectl delete job/migrate-job
</code></pre>

<p>The problem with this is (a) it doesn't show me the output which I like to see, and (b) it's 3 commands</p>

<h2>Method 2</h2>

<pre><code>kubectl run migrate --stdin --tty --rm --restart=Never --image=example.org/app/php:v-$(VERSION) --command -- ./artisan -vvv migrate
</code></pre>

<p>This almost works except I also need a volume mount to run this command, which AFAIK would require a rather lengthy <code>--overrides</code> arg. If I could pull the override in from a file instead it'd probably work well. Can I do that?</p>

<p>I also need to to return the exit code if the command fails.</p>

mpen
<p>There's an open ticket for this: <a href="https://github.com/kubernetes/kubernetes/issues/63214" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/63214</a></p>

<p>A short term solution is to run your job like this:</p>

<pre><code>kubectl run migrate --stdin --tty --rm --restart=Never --image=example.org/app/php:v-$(VERSION) --overrides="$(cat kubernetes/migrate.pod.yaml | y2j)"
</code></pre>

<p>Using <a href="https://github.com/wildducktheories/y2j" rel="nofollow noreferrer">y2j</a> to convert YAML to JSON so that I can use a standard pod manifest.</p>

<p><code>migrate.pod.yaml</code> looks like:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
    name: migrate-pod
spec:
    volumes:
        -   name: migrate-secrets-volume
            secret:
                secretName: google-service-account
    containers:
        -   name: migrate-container
            image: example.org/app/php
            command: ["./artisan",  "-vvv", "migrate"]
            stdin: true
            stdinOnce: true
            tty: true
            envFrom:
                -   secretRef:
                        name: dev-env
            volumeMounts:
                -   name: migrate-secrets-volume
                    mountPath: /app/secrets
                    readOnly: true
    restartPolicy: Never
    imagePullSecrets:
        -   name: regcred
</code></pre>
