KCNA Kubernetes Fundamentals Practice Question
You need to expose a set of pods running in the 'dev' namespace internally within the cluster on a stable IP. All pods have the label 'app: web'. Which kubectl command should you use?
⚠ Common exam trap
CNCF often tests the distinction between exposing a deployment (which uses a label selector for all pods) versus exposing a specific pod (which targets only that pod by name), leading candidates to choose Option D incorrectly.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
kubectl expose deployment web --port=80 --target-port=8080 --name=web-service -n dev
It exposes the existing deployment named 'web' (which manages pods with label 'app: web') as a ClusterIP service, providing a stable internal IP and DNS name within the cluster. The `--port=80` sets the service port, and `--target-port=8080` maps to the container port, ensuring traffic reaches the pods correctly in the 'dev' namespace.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
kubectl expose deployment web --port=80 --target-port=8080 --name=web-service -n dev
Why this is correct
If the pods are managed by a Deployment named 'web', this creates a Service that targets the pods.
- ✗
kubectl create service clusterip web --tcp=80:8080 -n dev
Why it's wrong here
This command creates a Service but requires manual selector specification; using `kubectl expose` is more direct for existing pods.
- ✗
kubectl run web --image=nginx --port=80 -n dev
Why it's wrong here
This creates a pod, not a Service.
- ✗
kubectl expose pod web --port=80 --target-port=8080 --name=web-service -n dev
Why it's wrong here
This command is for a single pod, not a set of pods.
Go deeper
Related to this question
About these practice questions
One of 833 original KCNA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This KCNA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the KCNA exam.