Kubernetes and Cloud Native Associate (KCNA)Kubernetes FundamentalsEasy
A developer is writing a YAML manifest for a new Pod that needs to run a container. The container image is hosted on Docker Hub. Which field in the Pod specification should be used to specify the image name and tag (e.g., `nginx:latest`) for the container?
- A`metadata.labels.image`
- B`spec.containers.image`
- C`spec.containers.name`
- D`spec.pod.image`
Show answer & explanationAnswer & explanation
Correct answer: B. `spec.containers.image`
Within the Pod specification, the `spec.containers` array defines individual containers, and each container object has an `image` field to specify the Docker image name and tag.
Why the other options are wrong
- A. `metadata.labels.image` is used for labeling the Pod with metadata, not for defining the container image itself.
- C. `spec.containers.name` specifies the name of the container within the Pod, not the image.
- D. There is no `spec.pod.image` field in a standard Pod specification.
Pod `image` field
The `image` field within a container's specification (`spec.containers[].image`) in a Kubernetes Pod manifest, used to define the Docker image to be pulled and run for that container.
- Located under `spec.containers`.
- Specifies the image name and optional tag (e.g., `myrepo/myimage:v1.0`).
- Crucial for defining the application's executable component.
Memory trick: Containers Contain Images and Names.