An image carries a default command. A Pod can replace it.
command and args
containers:
- name: box
image: busybox
command: ["sh", "-c"]
args: ["echo ready; sleep 3600"]| Field | Replaces in the image | Note |
|---|---|---|
command | ENTRYPOINT | The program |
args | CMD | Its arguments |
Set only args and the image's own command keeps running, with your arguments. Set command and the image's command is gone.
From kubectl run
Everything after -- is the container's arguments. --command makes it the command instead:
learner@shallows:~$ kubectl run box --image=busybox -- sleep 3600
pod/box created
learner@shallows:~$ kubectl run once --image=busybox --restart=Never --command -- sh -c 'echo hello market'
pod/once createdkubectl get pod once -o yaml shows where they landed: args for the first, command for the second.
A Pod lives as long as its command
The container ends when its command ends. Then the restartPolicy decides:
| Command ends | restartPolicy | You see |
|---|---|---|
| exit 0 | Always (default) | Restarted again and again: CrashLoopBackOff |
| exit 0 | Never | Completed, and it stays |
| exit 1 | OnFailure | Restarted |
This is why a Pod that runs echo hello with the default policy looks broken. It is not crashing; it is finishing, and being told to run for ever. A server command (nginx, sleep infinity) never ends, so it never restarts.