nerdexam
Linux_Foundation

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…

Submitted by yousef_jo· May 4, 2026Services and Networking

Question

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 in the ckad00017 nmespace exposing the cka00017-deployment Deployment on TCP port 8888

Exhibit

CKAD question #20 exhibit

Explanation

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 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

MistakeConsequence
Create Service before adding labelService selector may not include Role: userUI; endpoints won't reflect the labeled pods
Edit Deployment selector instead of pod template labelsKubernetes rejects the change (selectors are immutable after creation)
Remove existing pod labels when adding the new oneDeployment's own matchLabels breaks; rolling update fails or pods become unmanaged
Wrong namespace on either resourceResources 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

#Deployment scaling#Pod labels#NodePort Service#Service exposure

Community Discussion

No community discussion yet for this question.

Full CKAD Practice