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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With