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 container within that Pod always runs with a specific command and arguments, overriding the default command provided by the container image. Which field in the Pod definition should they configure for this purpose?

  1. A`spec.containers[].image`
  2. B`spec.containers[].ports`
  3. C`spec.containers[].command`
  4. D`spec.containers[].env`
Show answer & explanation

Correct answer: C. `spec.containers[].command`

The `command` field (and `args` field) in a container's specification allows you to override the default entrypoint and arguments defined in the container image, ensuring the container starts with a specific executable and parameters.

Why the other options are wrong

  • A. `image` specifies the container image to use, not the command to run within it.
  • B. `ports` defines which network ports the container exposes, unrelated to the execution command.
  • D. `env` defines environment variables for the container, not the executable command.

Container `command` and `args`

Fields in a Kubernetes container specification that define the entrypoint and arguments for the container, overriding image defaults.

  • `command` overrides the `ENTRYPOINT` in the Dockerfile.
  • `args` overrides the `CMD` in the Dockerfile (if `command` is also specified, `args` becomes arguments to `command`).
  • Used for customizing container execution behavior.

Memory trick: Command and Args are like giving direct instructions to your container.

More Kubernetes Fundamentals questions