Kubernetes and Cloud Native Associate (KCNA)Kubernetes FundamentalsMedium

A developer is writing a YAML manifest for a Pod and wants to ensure that a specific command is executed within the container when it starts, overriding the default command provided by the Docker image. Which field in the Pod's container specification should be used for this purpose?

  1. A`args`
  2. B`entrypoint`
  3. C`initContainers`
  4. D`command`
Show answer & explanation

Correct answer: D. `command`

In a Kubernetes Pod's container specification, the `command` field is used to specify the executable to run, overriding the `ENTRYPOINT` defined in the Docker image. The `args` field provides arguments to this command.

Why the other options are wrong

  • A. `args` provides arguments to the `command` (or image's `ENTRYPOINT`), not the command itself.
  • B. `entrypoint` is a Dockerfile instruction, not a Kubernetes Pod spec field for overriding.
  • C. `initContainers` run to completion before app containers start, for setup tasks, not to define the main application command.

Container `command` field

In a Pod's container specification, this field overrides the Docker image's `ENTRYPOINT` and defines the executable to be run when the container starts.

  • Overrides image's `ENTRYPOINT`.
  • Specifies the main executable.
  • Used with `args` for arguments.

Memory trick: Command: I command what to run!

More Kubernetes Fundamentals questions