Explain the main parts of a Kubernetes Deployment YAML.
apiVersion and kind identify the object, metadata names it, spec.replicas sets the count, spec.selector says which Pods it owns, and spec.template is the Pod blueprint whose labels must match the selector.
Explain it simply
A Deployment file is like an order form for a tiffin service: how many boxes (replicas), what goes in each box (template), and how to recognise your boxes (selector and labels).
apiVersion: apps/v1 and kind: Deployment say what this is. metadata.name names it. Under spec, replicas: 3 is the desired Pod count. selector.matchLabels is how the Deployment finds the Pods it owns. template is a full Pod spec with its own metadata.labels and containers; the template labels must include the selector labels, or Kubernetes rejects the YAML. Optional fields like strategy set how updates roll out.
Apply it with kubectl apply -f deploy.yaml. Editing the file and re-applying updates the same Deployment.
Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.27What to say in the interview
"A Deployment has apiVersion, kind, metadata, and a spec with replicas, a selector, and a Pod template. The template labels must match the selector so the Deployment can find its Pods."
Common mistakes
- Mismatch between selector.matchLabels and template labels.