CKAD · Question #20
First update the Deployment cka00017-deployment in the ckad00017 namespace: To run 2 replicas of the pod Add the following label on the pod: Role userUI Next, Create a NodePort Service named cherry…
CKAD/CKA Simulation: Update Deployment + Create NodePort Service Overall Goal You're doing two related things: 1. Modifying an existing Deployment to scale it and add a label to its pods 2. Exposing that Deployment via a NodePort Service so external traffic can reach it This is…
Question
Exhibit
Explanation
CKAD/CKA Simulation: Update Deployment + Create NodePort Service
Overall Goal
You're doing two related things:
- Modifying an existing Deployment to scale it and add a label to its pods
- Exposing that Deployment via a NodePort Service so external traffic can reach it
This is a classic "scale + expose" workflow. The label addition is critical because Services use label selectors to route traffic - if the Service and pods don't share matching labels, traffic never reaches the pods.
Step-by-Step Breakdown
Step 1 - Scale the Deployment to 2 replicas
kubectl -n ckad00017 edit deployment cka00017-deployment
# OR
kubectl -n ckad00017 scale deployment cka00017-deployment --replicas=2
Why: The question explicitly requires 2 replicas. More importantly, with a NodePort Service, having 2 replicas means kube-proxy load-balances traffic across both pods - this validates that your Service selector correctly targets the Deployment's pods, not just one.
If skipped: You lose points and the deployment won't match the desired state spec.
Step 2 - Add label Role: userUI to the pod template
In the Deployment's .spec.template.metadata.labels, add:
labels:
Role: userUI
# (keep existing labels too - don't remove them)
kubectl -n ckad00017 edit deployment cka00017-deployment
Why: This label goes on the pod template, not the Deployment itself. It will be inherited by all pods the Deployment creates. The NodePort Service you create next will use this label (or an existing one) as its selector.
Critical gotcha: Do NOT remove existing labels from the pod template - the Deployment's own selector (.spec.selector.matchLabels) must still match. If you break that match, Kubernetes will reject the change or orphan existing pods.
Step 3 - Create the NodePort Service named cherry
kubectl -n ckad00017 expose deployment cka00017-deployment \
--name=cherry \
--type=NodePort \
--port=8888 \
--target-port=<container-port>
Or via kubectl create service nodeport:
kubectl -n ckad00017 create service nodeport cherry \
--tcp=8888:<container-port>
Then verify the selector matches the pods:
kubectl -n ckad00017 get service cherry -o yaml
kubectl -n ckad00017 get endpoints cherry
Why NodePort: NodePort exposes the Service on a static port (30000–32767) on every node's IP, making it reachable from outside the cluster without a load balancer - typical for on-prem/exam environments.
Why port 8888: This is the Service's port (what clients connect to), not necessarily the container's port. --target-port maps to the actual container port.
If you skip Step 2 first: The Service's selector may not match your pods (especially if the exam validator checks for the Role: userUI label), resulting in no endpoints and broken connectivity.
What Goes Wrong If Steps Are Out of Order
| Mistake | Consequence |
|---|---|
| Create Service before adding label | Service selector may not include Role: userUI; endpoints won't reflect the labeled pods |
| Edit Deployment selector instead of pod template labels | Kubernetes rejects the change (selectors are immutable after creation) |
| Remove existing pod labels when adding the new one | Deployment's own matchLabels breaks; rolling update fails or pods become unmanaged |
| Wrong namespace on either resource | Resources exist but are isolated from each other |
Memory Tip
"Label → Scale → Expose" - think of it as preparing the pods first, then connecting the network to them.
Pods wear labels like name tags. The Service is a receptionist who only lets in guests whose name tag matches. Always put the name tag on before the receptionist starts their shift.
Topics
Community Discussion
No community discussion yet for this question.
