A Deployment in Kubernetes manages a set of identical pods. It ensures the desired number of pods are running and updates them smoothly when changes happen.
Click to reveal answer
beginner
Which YAML field specifies the number of pod replicas in a Deployment?
The spec.replicas field sets how many pod copies Kubernetes should run.
Click to reveal answer
intermediate
What does the selector field do in a Deployment YAML?
The selector tells Kubernetes which pods belong to this Deployment by matching labels.
Click to reveal answer
intermediate
Why is the template section important in a Deployment YAML?
The template defines the pod's configuration, like containers and labels, that the Deployment will create.
Click to reveal answer
intermediate
How do you update a Deployment to use a new container image?
Change the spec.template.spec.containers[].image field to the new image version and apply the YAML. Kubernetes will update pods smoothly.
Click to reveal answer
Which field in a Deployment YAML specifies the pod labels to match?
Aspec.replicas
Bmetadata.labels
Cspec.template.spec.containers
Dspec.selector.matchLabels
✗ Incorrect
The spec.selector.matchLabels field defines which pods belong to the Deployment by matching their labels.
What happens if you set spec.replicas to 3?
AKubernetes ignores the setting
BKubernetes runs 3 copies of the pod
CKubernetes runs 1 pod only
DKubernetes deletes all pods
✗ Incorrect
Setting spec.replicas to 3 tells Kubernetes to keep 3 pod copies running.
Where do you specify the container image in a Deployment YAML?
Aspec.selector
Bmetadata.name
Cspec.template.spec.containers[].image
Dspec.replicas
✗ Incorrect
The container image is set inside spec.template.spec.containers[].image.
What is the purpose of the metadata.name field in a Deployment YAML?
AIt names the Deployment resource
BIt sets the container image
CIt defines pod labels
DIt specifies the number of replicas
✗ Incorrect
metadata.name gives the Deployment a unique name in the cluster.
How does Kubernetes update pods when you change the container image in a Deployment?
AIt creates new pods with the new image and deletes old ones gradually
BIt deletes all pods immediately
CIt ignores the change
DIt restarts the cluster
✗ Incorrect
Kubernetes performs a rolling update by creating new pods with the new image and removing old pods smoothly.
Explain the key sections of a Kubernetes Deployment YAML and their roles.
Think about how Kubernetes knows what pods to run and how many.
You got /4 concepts.
Describe how you would update a Deployment to use a new version of a container image.
Focus on the image field and what happens after applying changes.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of a Deployment in Kubernetes when defined using a YAML file?
easy
A. To manage and update multiple copies of an application smoothly
B. To store data persistently across pods
C. To expose an application to the internet
D. To define network policies between pods
Solution
Step 1: Understand Deployment role
A Deployment manages the lifecycle of pods, ensuring the desired number of replicas run and updates happen smoothly.
Step 2: Compare options
Options B, C, and D describe other Kubernetes resources (PersistentVolume, Service, NetworkPolicy), not Deployment.
Final Answer:
To manage and update multiple copies of an application smoothly -> Option A
Quick Check:
Deployment = Manage app replicas and updates [OK]
Hint: Deployments control app copies and updates, not storage or networking [OK]
Common Mistakes:
Confusing Deployment with Service or PersistentVolume
Thinking Deployment exposes apps externally
Assuming Deployment manages network policies
2. Which of the following YAML snippets correctly sets the number of pod replicas to 3 in a Deployment?
easy
A. replicas: 3
B. replicaCount: 3
C. count: 3
D. podReplicas: 3
Solution
Step 1: Identify correct replicas field
The correct field to specify pod count in Deployment YAML is replicas.
Step 2: Check other options
Fields like replicaCount, count, or podReplicas are invalid and will cause errors.
Final Answer:
replicas: 3 -> Option A
Quick Check:
Use 'replicas' to set pod count [OK]
Hint: Use 'replicas' exactly to set pod count in Deployment YAML [OK]
Common Mistakes:
Using incorrect field names like replicaCount
Misspelling 'replicas' or using camelCase
Placing replicas under wrong YAML level
3. Given this Deployment YAML snippet, what will be the label selector used to match pods?
selector:
matchLabels:
app: myapp
tier: frontend
medium
A. Pods with any label app or tier
B. Pods with label app=myapp only
C. Pods with label tier=frontend only
D. Pods with labels app=myapp and tier=frontend
Solution
Step 1: Understand matchLabels selector
The matchLabels requires all listed labels to match exactly for pod selection.
Step 2: Analyze given labels
Both app: myapp and tier: frontend must be present on pods to match.
Final Answer:
Pods with labels app=myapp and tier=frontend -> Option D
Quick Check:
matchLabels means all labels must match [OK]
Hint: matchLabels requires all labels to match exactly [OK]
Common Mistakes:
Assuming matchLabels matches any one label
Confusing matchLabels with matchExpressions
Ignoring one of the labels in selector
4. You wrote this Deployment YAML but your pods are not created. What is the error?
The selector matchLabels: app: webapp does not match template labels: app: frontend. Labels must match exactly or Deployment creation fails.
Step 2: Verify other fields
Ports are optional for pod creation; apiVersion is correct; image tag defaults to latest.
Final Answer:
Selector labels do not match template labels -> Option C
Quick Check:
Selector must match template labels [OK]
Hint: Selector labels must exactly match template labels [OK]
Common Mistakes:
Assuming container ports are required for pod creation
Thinking image tag is mandatory
Confusing apiVersion for Deployment
5. You want to update your Deployment to run 5 replicas and change the container image to 'nginx:1.21'. Which YAML snippet correctly applies both changes?