snippetkubernetesMinor
How to run short-lived command using kubectl
Viewed 0 times
shortlivedkubectlusinghowcommandrun
Problem
I was trying to measure pod startup time buy running the following:
At first it seems like this command takes a long time to start the pod. However if you run
At first the command succeeds:
Then transitions to
The logs show that the command ran successfully.
It is unclear to me why the pod is transitioning from
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 -- date
error: timed out waiting for the conditionAt 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 2sThen transitions to
CrashLoopBackOff.% kubectl get pods
NAME READY STATUS RESTARTS AGE
test 0/1 CrashLoopBackOff 1 7sThe logs show that the command ran successfully.
% kubectl logs test
Thu Jan 27 15:02:36 UTC 2022It 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 10Solution
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 -- dateCode Snippets
% 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 -- dateContext
StackExchange DevOps Q#15345, answer score: 2
Revisions (0)
No revisions yet.