Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: when do i need to add /bin/sh -c to my command?

I am preparing for the CKAD exam and I am doing practice with the questions provide here

I have a doubt over this two different way of executing commands. Here the example provided is with a job but I think the question might be more general and extendable to all containers.

Under the job exercises there are two requests:

Create a job named pi with image perl that runs the command with arguments "perl -Mbignum=bpi -wle 'print bpi(2000)'"

kubectl create job pi  --image=perl -- perl -Mbignum=bpi -wle 'print bpi(2000)'

Create a job with the image busybox that executes the command 'echo hello;sleep 30;echo world

kubectl create job busybox --image=busybox -- /bin/sh -c 'echo hello;sleep 30;echo world'

Why in the second command I need to provide /bin/sh -c as well?

How could I understand when to use it and when not?

like image 350
Cr4zyTun4 Avatar asked Nov 15 '25 08:11

Cr4zyTun4


1 Answers

Because in first example

kubectl create job pi  --image=perl -- perl -Mbignum=bpi -wle 'print bpi(2000)'

you call a perl interpreter, perl -Mbignum=bpi -wle 'print bpi(2000)'

and in second example you call a bash shell command, echo hello;sleep 30;echo world therefore /bin/sh -c

kubectl create job busybox --image=busybox -- /bin/sh -c 'echo hello;sleep 30;echo world'

The -- is saying after this it is a command is executed inside the container.

like image 145
bodo Avatar answered Nov 18 '25 19:11

bodo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!