I create a simple executable binary file program
that runs forever:
// pseudocode
while (true) {
print("Sleeping")
sleep(seconds(1));
}
Then I dockerise this program using such Dockerfile
:
FROM debian:10
ADD program /
ENTRYPOINT ["/program"]
Then I build and push docker image to a global repository:
docker build -t docker:5000/program .
docker push docker:5000/program
Then I create a deploy.yaml
file for this program to be run on a kubernetes pod:
apiVersion: v1
kind: Pod
metadata:
name: program
namespace: my_namespace
spec:
containers:
- name: program
image: docker:5000/program
imagePullPolicy: Always
command: ["echo", "SUCCESS"]
Finally, I start the program on kubernetes:
kubectl create -f deploy.yaml
However, the kubectl describe pods -n my_namespace program
reports:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 27m default-scheduler Successfully assigned
mariusl/ingress to mma7-standard5-ime
Normal Created 26m (x4 over 27m) kubelet, mma7-standard5-ime Created container
ingress
Normal Started 26m (x4 over 27m) kubelet, mma7-standard5-ime Started container
ingress
Normal Pulling 25m (x5 over 27m) kubelet, mma7-standard5-ime Pulling image
"docker:5000/program"
Normal Pulled 25m (x5 over 27m) kubelet, mma7-standard5-ime Successfully pulled
image "docker:5000/program"
Warning BackOff 2m (x117 over 27m) kubelet, mma7-standard5-ime Back-off restarting
failed container
Which, in my interpretation means, that the program fails to get executed and gets repeatedly restarted. Why can this happen?
Your container executes echo "SUCCESS" and terminates, see https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes
command
in kubernetes overrides entrypoint
in docker. But this does not explain why the container is failed.
Your pod is configured with command: ["echo", "SUCCESS"]
which will overwrite the ENTRYPOINT ["/program"]
and hence, your container will only echo SUCCESS
and terminate immediately.
Note that in Kubernetes, command
will overwrite entrypoint
in Docker container and args
will overwrite cmd
in Docker container.
You can remove the line command: ["echo", "SUCCESS"]
and the pod will be up and running!
When you override the default Entrypoint and Cmd, these rules apply: read here
1) If you do not supply command or args for a Container, the defaults defined in the Docker image are used.
2) If you supply a command but no args for a Container, only the supplied command is used. The default EntryPoint and the default Cmd defined in the Docker image are ignored.
3) If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
4) If you supply a command and args, the default Entrypoint and the default Cmd defined in the Docker image are ignored. Your command is run with your args.