CKA · Question #56
You must connect to the correct host. Failure to do so may result in a zero score. [candidate@base] $ ssh Cka000022 Task Reconfigure the existing Deployment front-end in namespace spline-reticulator…
CKA Exam Question: Exposing a Deployment and Creating a NodePort Service --- Overall Goal You need to do two things: 1. Add a containerPort declaration to the nginx container in the front-end Deployment (so Kubernetes knows which port the app listens on). 2. Create a NodePort…
Question
Exhibits
Explanation
CKA Exam Question: Exposing a Deployment and Creating a NodePort Service
Overall Goal
You need to do two things:
- Add a
containerPortdeclaration to thenginxcontainer in thefront-endDeployment (so Kubernetes knows which port the app listens on). - Create a NodePort Service named
front-end-svcthat routes traffic to port 80 of those pods.
The reason this is the correct approach: In Kubernetes, a containerPort in a Pod spec is informational (traffic works without it), but it's required by exam convention and best practice. The Service is what actually makes the app reachable - either cluster-internally or externally via a node's IP.
Step-by-Step Walkthrough
Step 1: SSH to the correct host
ssh Cka000022
The exam runs multiple clusters. Working on the wrong one means modifying the wrong objects - guaranteed zero. Always SSH first.
Step 2: Set the namespace context (optional but safe)
kubectl config set-context --current --namespace=spline-reticulator
Prevents accidentally editing resources in default. Not strictly required if you use -n on every command, but reduces error risk.
Step 3: Edit the Deployment to expose port 80
kubectl edit deployment front-end -n spline-reticulator
In the spec.template.spec.containers section for the nginx container, add:
ports:
- containerPort: 80
Why: The question says "reconfigure the existing Deployment to expose port 80." This is what "expose the port" means in a Deployment context - declaring it in the container spec. Without this, the Service can still work, but you'll lose marks because the task explicitly asks for it.
If skipped: You'll likely lose partial credit for the Deployment portion of the task, even if the Service works.
Step 4: Create the NodePort Service
kubectl expose deployment front-end \
--name=front-end-svc \
--port=80 \
--target-port=80 \
--type=NodePort \
-n spline-reticulator
Or imperatively generate + apply:
kubectl expose deployment front-end --name=front-end-svc --port=80 --type=NodePort -n spline-reticulator
Why each flag matters:
| Flag | Purpose |
|---|---|
--name=front-end-svc | Exact name required by the task |
--port=80 | The Service's cluster-facing port |
--target-port=80 | The container port traffic is forwarded to |
--type=NodePort | Exposes the Service on a static port on every node's IP |
kubectl expose deployment automatically copies the Deployment's label selector, so the Service correctly targets the pods - this is why exposing a Deployment is cleaner than writing a Service manifest from scratch.
If you use --type=ClusterIP instead: The Service won't be accessible from outside the cluster, failing the "expose via NodePort" requirement.
If the name is wrong: The grader does an exact-match lookup - wrong name = zero for this part.
Step 5: Verify
kubectl get svc front-end-svc -n spline-reticulator
kubectl describe svc front-end-svc -n spline-reticulator
Confirm: TYPE is NodePort, PORT(S) shows 80:3XXXX/TCP, and Selector matches the Deployment's pod labels.
What Goes Wrong If Steps Are Out of Order
- Creating the Service before editing the Deployment is fine functionally, but if the Deployment has no
containerPortyet,kubectl exposemay not infer--target-portcorrectly in some versions. Set the port first to be safe. - Skipping the namespace flag on any command silently operates on
default, and you'll edit/create nothing inspline-reticulator.
Memory Tip
"Declare, then Expose" - First declare the port on the container (Deployment edit), then expose it to the outside world (Service creation). Think of it like opening a window (containerPort) and then building a door to it (NodePort Service).
The key kubectl verb to remember: kubectl expose deployment - it does the selector wiring for you automatically.
Topics
Community Discussion
No community discussion yet for this question.

