Complete a minimal Deployment manifest for an app with 3 replicas and a container port.
Complete a minimal Deployment for a stateless web app.
Constraints: run 3 replicas; the container listens on port 8080; keep the selector and the Pod-template labels consistent. Do not add a Service or probes — just a valid Deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: # ??? how many
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
# declare the container port here
Fill in the replica count and the container port.
Set spec.replicas: 3 and add ports under the container with containerPort: 8080. The selector.matchLabels must match template.metadata.labels (app: web), or the Deployment adopts no Pods and the apply is rejected. apiVersion is apps/v1, kind is Deployment; the template is the Pod spec the ReplicaSet stamps out three times.
- ✗Selector labels not matching the template labels, so no Pods are managed
- ✗Putting
containerPortorreplicasat the wrong nesting level - ✗Using
kind: Pod/apiVersion: v1instead ofDeployment/apps/v1
- →What does the API reject at apply time if the selector does not match the template labels?
- →Why is
containerPortinformational rather than what actually exposes the app?
Solution
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 8080
diverge, the apiserver rejects the object — the Deployment could adopt no Pods. containerPort is informational (it documents the port); a Service, not this field, is what actually routes traffic to the app.
replicas: 3lives at the Deployment'sspeclevel (not on the container).- The port is declared as a
portslist withcontainerPort: 8080inside the container. selector.matchLabels(app: web) must equaltemplate.metadata.labels. If they