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?
3
Answers
Your container executes echo “SUCCESS” and terminates, see
https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes
command
in kubernetes overridesentrypoint
in docker. But this does not explain why the container is failed.Your pod is configured with
command: ["echo", "SUCCESS"]
which will overwrite theENTRYPOINT ["/program"]
and hence, your container will onlyecho SUCCESS
and terminate immediately.Note that in Kubernetes,
command
will overwriteentrypoint
in Docker container andargs
will overwritecmd
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