nerdexam
Linux_Foundation

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…

Submitted by manish99· May 4, 2026Services and Networking

Question

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 to expose port 80/tcp of the existing container nginx. Create a new Service named front-end-svc exposing the container port 80/tcp . Configure the new Service to also expose the individual Pods via a NodePort .

Exhibits

CKA question #56 exhibit 1
CKA question #56 exhibit 2

Explanation

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 Service named front-end-svc that 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:

FlagPurpose
--name=front-end-svcExact name required by the task
--port=80The Service's cluster-facing port
--target-port=80The container port traffic is forwarded to
--type=NodePortExposes 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 containerPort yet, kubectl expose may not infer --target-port correctly 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 in spline-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

#Deployments#Services#NodePort#Container Port Exposure

Community Discussion

No community discussion yet for this question.

Full CKA Practice