CKA Services and Networking Practice Question
You run: kubectl expose deployment web --port=80 --target-port=8080 --type=LoadBalancer --name=web-svc. What is the effect of this command?
⚠ Common exam trap
It's easy for candidates to think `kubectl expose deployment` selects all pods in the namespace or requires an explicit label selector, when in fact it automatically uses the deployment's pod template labels, and the `--type=LoadBalancer` immediately creates a LoadBalancer Service, not a ClusterIP that is later upgraded.
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
✓
Creates a Service that selects pods with label 'app=web' and maps port 80 to 8080
The `kubectl expose deployment web --port=80 --target-port=8080 --type=LoadBalancer --name=web-svc` command creates a Service named 'web-svc' that automatically inherits the label selector from the 'web' deployment (typically `app=web`). It maps the Service's port 80 to the pods' container port 8080, and the `--type=LoadBalancer` sets the Service type to LoadBalancer, which provisions an external load balancer (if supported by the cluster) and also creates a NodePort and ClusterIP automatically.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Creates a Service of type ClusterIP which is later changed to LoadBalancer
Why it's wrong here
The `kubectl expose` command, when used without the `--type` flag, defaults to creating a Service of type `ClusterIP`. This Service type provides internal cluster access only and does not automatically transition to a `LoadBalancer` type. Changing a Service's type to `LoadBalancer` after creation would require a separate `kubectl edit` or `kubectl patch` operation, or specifying `--type=LoadBalancer` directly during the initial `expose` command execution.
- ✓
Creates a Service that selects pods with label 'app=web' and maps port 80 to 8080
Why this is correct
When `kubectl expose` is used with a Deployment, the resulting Service automatically inherits the Deployment's label selector. For a Deployment named 'web', this selector is typically `app=web`, ensuring the Service routes traffic exclusively to the pods managed by that specific Deployment. The command specifies the Service will listen on `port 80`, and the context implies the Deployment's containers are listening on `target-port 8080`, establishing the mapping from Service port 80 to pod port 8080.
- ✗
Creates a Service that selects all pods in the namespace regardless of labels
Why it's wrong here
The `kubectl expose deployment` command creates a Service that specifically targets the pods managed by the specified Deployment. It achieves this by automatically inheriting the Deployment's label selector (e.g., `app=web`), which precisely identifies the relevant pods. Services are fundamentally designed to route traffic to a selected group of pods based on their labels, not indiscriminately to all pods within a given namespace.
- ✗
Creates a Service that exposes port 8080 on the node
Why it's wrong here
The `kubectl expose` command, when executed without a `--type` flag, defaults to creating a `ClusterIP` Service. A `ClusterIP` Service makes the application accessible only from within the Kubernetes cluster and does not expose any ports directly on the cluster nodes. Exposing a port on the node would require explicitly specifying `--type=NodePort`, which would then allocate a high-numbered port on each node, mapping it to the Service's port.
Go deeper
Related to this question
Learn chapter
Configuring Core Cluster Components
Key term
kubectl Command Reference
kubectl is the command-line tool used to interact with and manage Kubernetes clusters by sending commands to the Kubernetes API.
Key term
ClusterIP NodePort LoadBalancer
ClusterIP, NodePort, and LoadBalancer are three types of Kubernetes Services that control how traffic reaches your application pods inside the cluster or from outside.
About these practice questions
This CKA question is part of Courseiva's 302-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKA 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 CKA exam.