Change entrypoint of a k8s Pod, but keep the CMD
Asked Answered
I

1

5

How to change the Docker ENTRYPOINT in a Kubernetes deployment, without changing also the Docker CMD?

In the Pod I would do

image: "alpine"
entrypoint: "/myentrypoint"

but this overwrites either ENTRYPOINT and the CMD from the Dockerfile.

The documentation doesn't mention it, but seems like a big use-case missed.

Ixtle answered 9/6, 2021 at 21:22 Comment(6)
Most cases of changing a container's entrypoint also reset the command; both Dockerfile ENTRYPOINT and docker run --entrypoint also reset the command part. Do you have a more specific use case where you want to reset the entrypoint (Kubernetes command:) but keep the command (Kubernetes args:)?Messenia
ENTRYPOINT is used whit docker exec, while CMD is the default with docker run when nothing is specified. I'm ok with the default run service (specified with CMD), FROM the image I am extending. But I want to customise its ENTRYPOINT script to handle specific exec commands.Ixtle
I know I can use command together with args, but I do not want to manually keep in sync with the base image (that I have no control on). It's inconvenient when having: BaseImageWithCMD -> MyBaseImage -> MyActualImage -> KubernetesWithCustomENTRYPOINTIxtle
Both the entrypoint part and the command part are used when you start a container (concatenated into a single command with arguments). Neither is used in either docker exec or kubectl exec. Again, a more specific use case might help suggest a different approach.Messenia
My use case is to extend the entrypoint functionality, for when I use kubectl exec on the container running in the pod. I want to perform additional checks (that the base image entrypoint does not), when executing a non-default command,Ixtle
"Neither is used in either docker exec or kubectl exec" - I was missing this detail and wrongly expected ENTRYPOINT to be called at every access to the container, as it happens with docker run --rm -i ... I ended up adding it explicitly into kubectl exec deploy/mint -- /myentrypoint $@.Ixtle
H
10

That's not a thing.

  • ENTRYPOINT (in Dockerfile) is equal to command: (in PodSpec)
  • CMD (in Dockerfile) equals args: (in PodSpec)

So just override command but not args.

Horowitz answered 9/6, 2021 at 22:13 Comment(2)
If you check the notes, in the linked documentation above, there's written: "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."Ixtle
Yes, you need to restate the values but you don't need to change them.Horowitz

© 2022 - 2024 — McMap. All rights reserved.