<p>Say I want to deploy a pod with skaffold that will <em>not</em> contain a continuously running/blocking program. E.g. take the <a href="https://github.com/GoogleContainerTools/skaffold/tree/master/examples/getting-started" rel="nofollow noreferrer">getting started example</a> and change <code>main.go</code> to:</p>

<pre><code>package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello world!")
}
</code></pre>

<p>If I run <code>skaffold dev</code> with the above modified example and just wait without making any changes to the code, the pod will continuously restart, cycling through statuses <code>Completed</code> -> <code>CrashLoopBackOff</code> -> <code>Completed</code>, with each restart running the program in the pod again. How do I get the pod to run the program once while only rerunning/restarting the pod on changes to the code?</p>

<p>This is with skaffold v1.6.0-docs, ubuntu 18, microk8s 1.16/stable, having set <code>skaffold config set default-repo localhost:32000</code>.</p>

lsimmons
<p>First of all I would like to emphasize that there is nothing specific to <strong>Skaffold</strong>. It is rather related with the very nature of kubernetes <code>Pod</code> which is not meant to run to completion but rather keep running (at least with its default settings).</p>

<p>You can easily verify it by running a <code>Pod</code> from <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/#pod-templates" rel="nofollow noreferrer">this</a> example in a few differant variants:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox
    command: ['sh', '-c', 'echo Hello Kubernetes! &amp;&amp; sleep 3600']
</code></pre>

<p>Try to reduce sleep time to some shorter value and you'll observe that it is also constantly changing between <code>Completed</code> and <code>CrashLoopBackOff</code> states. It will also happen when you remove the command which keeps the container up and running.</p>

<p>If you run:</p>

<pre><code>kubectl get pod myapp-pod -o yaml
</code></pre>

<p>you may notice that there is <code>restartPolicy</code> defined in <code>Pod</code> specification and if you don't set it explicitely to a different value, by default it is set to <code>Always</code>. Here you have the reason why your <code>Completed</code> <code>Pods</code> are constantly restarted.</p>

<p><strong>Setting it to <code>Never</code> should give you the result you want to achieve.</strong>:</p>

<pre><code>spec:
  restartPolicy: Never
  containers:
  - name: myapp-container
    image: busybox
    ...
</code></pre>

<p>However bear in mind that you typically won't be using bare <code>Pods</code> for running your workload in <strong>kubernetes</strong>. You will rather use controllers such as <code>Deployment</code> that manage them. As long as <code>Deployment</code> is used to ensure that certain set of <code>Pods</code> is up and running, <strong>for running something to completion</strong> you have in <strong>kubernetes</strong> another controller, named <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" rel="nofollow noreferrer">Job</a>.</p>
