<p>Created a pod using following command </p>

<pre><code> kubectl run bb --image=busybox --generator=run-pod/v1 --command -- sh -c "echo hi"
</code></pre>

<p>Pod is getting created repeatedly </p>

<pre><code>bb    1/1   Running             1     7s
bb    0/1   Completed           1     8s
bb    0/1   CrashLoopBackOff    1     9s
bb    0/1   Completed           2     22s
bb    0/1   CrashLoopBackOff    2     23s
bb    0/1   Completed           3     53s
</code></pre>

<p>exit code is 0</p>

<pre><code>k describe pod bb

...

    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 29 Aug 2019 22:58:36 +0000
      Finished:     Thu, 29 Aug 2019 22:58:36 +0000
    Ready:          False
    Restart Count:  7

</code></pre>

<p>Thanks</p>

Chaminda
<p><code>kubectl run</code> defaults to setting the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy" rel="nofollow noreferrer">"restart policy"</a> to "Always". It also sets up a Deployment in this case, to manage the pod.</p>

<pre><code>--restart='Always': The restart policy for this Pod.  Legal values
 [Always, OnFailure, Never].  If set to 'Always' a deployment is created,
 if set to 'OnFailure' a job is created, if set to 'Never', a regular pod
 is created. For the latter two --replicas must be 1.  Default 'Always',
 for CronJobs `Never`.
</code></pre>

<p>If you change the command to:</p>

<pre><code>kubectl run bb \
  --image=busybox \
  --generator=run-pod/v1 \
  --restart=Never \
  --command -- sh -c "echo hi"
</code></pre>

<p>A Job will be setup and the pod won't be restarted. </p>

<h3>Outside of <code>kubectl run</code></h3>

<p>All <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#podspec-v1-core" rel="nofollow noreferrer">pod specs</a> will include a <code>restartPolicy</code>, which defaults to <code>Always</code> so must be specified if you want different behaviour.</p>

<pre><code>spec:
  template:
    spec:
      containers:
      - name: something
      restartPolicy: Never
</code></pre>

<p>If you are looking to run a task to completion, try a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" rel="nofollow noreferrer">Job</a> instead. </p>
