What is wrong in this command -> kubectl run busybox --image=busybox -- /bin/ . . .

vikas mahajan:
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx
spec:
containers:

  • name: hello
    image: nginx
    command:
    • /bin/sh
    • -c
    • date; sleep 3

vikas mahajan:
controlplane $ kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 0/1 CrashLoopBackOff 5 5m58s

vikas mahajan:
It ran fine for first 2-3 times and now started crashing

vikas mahajan:
Does it mean that after every 3 seconds container is restarting which causes an issue ?

chris resnik:
the yaml looks fine… but again: with sleep 3, the container will terminate after outputting the date and then sleeping for 3 seconds

chris resnik:
try using the date command only as imperative command with the interactive switch, then you will see the output and then see the pod shutting down

chris resnik:
kubectl run bb -it --image=busybox --restart=Never — date

chris resnik:
should work but I don’t have a kubectl console atm

vikas mahajan:
No issues … i will check

vikas mahajan:
One more doubt, using the above yaml with “sleep 3” … --restart=Never means pod should restart again and again whether its failed or completed successfully ? In our case its running fine 2,3 times and then starts crashing

vikas mahajan:
Ideally it should never go into CrashLoopBackOff

chris resnik:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/