Kubernetes and Cloud Native Associate (KCNA)Kubernetes FundamentalsEasy

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

  1. Acommand
  2. Bargs
  3. Cimage
  4. Denv
Show answer & explanation

Correct answer: A. command

The `command` field in a container specification allows you to override the default entrypoint of the Docker image. If `command` is specified, it replaces the `ENTRYPOINT` defined in the Docker image.

Why the other options are wrong

  • B. `args` specifies arguments to the `command` or the image's `ENTRYPOINT`, not the command itself.
  • C. `image` specifies the container image to use, not the command to execute.
  • D. `env` defines environment variables for the container, not the executable command.

Container `command` field

The `command` field in a Kubernetes container specification allows users to override the default `ENTRYPOINT` defined in the Docker image.

  • Overrides the Docker image's `ENTRYPOINT`.
  • If `args` are also specified, they become the arguments to this `command`.
  • Defined as a list of strings.

Memory trick: Command sets the 'C'ore 'C'ode to run.

More Kubernetes Fundamentals questions