<p>Ah, shortly after posting I found a clean solution. Adding <code>--restart=Never</code> makes the command work as expected.</p>
<pre><code>% time kubectl run -n kcox-test --image busybox --attach test --restart=Never -- date
Thu Jan 27 15:10:41 UTC 2022
time Total: 9.449 (1%), User: 0.100, System: 0.034  - kubectl run -n kcox-test --image busybox --attach test --restart=Never -- date
</code></pre>

CC BY-SA 4.0
2022-02-28T06:59:39.660Z
Also add --rm to have the pod removed automatically
Serve Laurijssen
CC BY-SA 4.0
2022-01-27T15:11:10.477Z
2022-01-27T15:11:10.477Z
Kevin Cox
<p>I was trying to measure pod startup time buy running the following:</p>
<pre><code>% kubectl run --image busybox --attach test -- date
error: timed out waiting for the condition
</code></pre>
<p>At first it seems like this command takes a long time to start the pod. However if you run <code>kubectl get pods</code> while it is running you see something interesting.</p>
<p>At first the command succeeds:</p>
<pre><code>% kubectl get pods
NAME   READY   STATUS      RESTARTS   AGE
test   0/1     Completed   0          2s
</code></pre>
<p>Then transitions to <code>CrashLoopBackOff</code>.</p>
<pre><code>% kubectl get pods
NAME   READY   STATUS             RESTARTS   AGE
test   0/1     CrashLoopBackOff   1          7s
</code></pre>
<p>The logs show that the command ran successfully.</p>
<pre><code>% kubectl logs test 
Thu Jan 27 15:02:36 UTC 2022
</code></pre>
<p>It is unclear to me why the pod is transitioning from <code>Completed</code> to <code>CrashLoopBackOff</code>. Is there a way to make <code>kubectl</code> do the right thing in this scenario?</p>
<hr />
<p>The best work-around I have found so far is to use a slower command and subtract the delay from my testing.</p>
<pre><code>% kubectl run --image busybox --attach test -- sleep 10
</code></pre>

<kubernetes><kubectl>
How to run short-lived command using kubectl
Kevin Cox
# How to run short-lived command using kubectl

(Asked by: username_0 on 2022-01-27)

I was trying to measure pod startup time buy running the following:
% kubectl run --image busybox --attach test -- date
error: timed out waiting for the condition

At first it seems like this command takes a long time to start the pod. However if you run kubectl get pods while it is running you see something interesting.
At first the command succeeds:
% kubectl get pods
NAME   READY   STATUS      RESTARTS   AGE
test   0/1     Completed   0          2s

Then transitions to CrashLoopBackOff.
% kubectl get pods
NAME   READY   STATUS             RESTARTS   AGE
test   0/1     CrashLoopBackOff   1          7s

The logs show that the command ran successfully.
% kubectl logs test 
Thu Jan 27 15:02:36 UTC 2022

It is unclear to me why the pod is transitioning from Completed to CrashLoopBackOff. Is there a way to make kubectl do the right thing in this scenario?

The best work-around I have found so far is to use a slower command and subtract the delay from my testing.
% kubectl run --image busybox --attach test -- sleep 10

**Tags:** kubernetes, kubectl


---

## 1 answers

### Answer by username_0 on 2022-01-27. Score: 2 | Accepted answer

Ah, shortly after posting I found a clean solution. Adding --restart=Never makes the command work as expected.
% time kubectl run -n kcox-test --image busybox --attach test --restart=Never -- date
Thu Jan 27 15:10:41 UTC 2022
time Total: 9.449 (1%), User: 0.100, System: 0.034  - kubectl run -n kcox-test --image busybox --attach test --restart=Never -- date

> **Comments:**
> **username_1**: Also add --rm to have the pod removed automatically  

---

