Which of the following is the correct syntax to specify the container image in a Deployment YAML?
easy📝 Syntax Q3 of 15
Kubernetes - ReplicaSets and Deployments
Which of the following is the correct syntax to specify the container image in a Deployment YAML?
Acontainers:
- name: app
image: nginx:latest
Bcontainers:
- image: nginx:latest
name: app
Ccontainer:
name: app
image: nginx:latest
Dcontainers:
name: app
image: nginx:latest
Step-by-Step Solution
Solution:
Step 1: Check correct container list syntax
The containers field is a list indicated by a dash (-). Each container must have a name and image.
Step 2: Validate correct order and keys
containers:
- name: app
image: nginx:latest correctly uses a list with dash, name first, then image. containers:
- image: nginx:latest
name: app reverses keys but is valid YAML; however, Kubernetes expects name first by convention. Options C and D have syntax errors (missing list or wrong key).
Final Answer:
containers:
- name: app
image: nginx:latest -> Option A
Quick Check:
Container list uses dash and name/image keys [OK]
Quick Trick:Use dash (-) for containers list with name and image keys [OK]
Common Mistakes:
Missing dash for list items
Using singular container instead of containers
Incorrect indentation or key order
Master "ReplicaSets and Deployments" in Kubernetes
9 interactive learning modes - each teaches the same concept differently