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 when the container starts, overriding the default command provided by the Docker image. Which field within the container specification should be used for this purpose?
- Aenv
- Blifecycle
- Ccommand
- Dargs
Show answer & explanationAnswer & explanation
Correct answer: C. command
The `command` field in a container's specification allows you to override the default entrypoint (`ENTRYPOINT`) of the Docker image. This is the correct field for specifying the executable to run.
Why the other options are wrong
- A. `env` is used to set environment variables for the container, not to define its startup command.
- B. `lifecycle` hooks define actions to take at certain points in a container's lifecycle (e.g., postStart, preStop), not the initial command.
- D. `args` provides arguments to the entrypoint/command, it does not override the command itself.
Container command field
The `command` field in a Kubernetes container specification allows overriding the `ENTRYPOINT` defined in the Docker image, specifying the executable to run.
- Overrides the image's `ENTRYPOINT`.
- Corresponds to the `CMD` instruction if `ENTRYPOINT` is not set.
- Should be an array of strings (executable and its fixed arguments).
- `args` field provides additional arguments.
Memory trick: Command the Entrypoint, Args for the CMD.