Courseiva
Services and Networking →easyMultiple Choice

CKAD Services and Networking Practice Question

Which of the following commands creates a LoadBalancer Service named `web-svc` for a Deployment named `web` on port 80?

⚠ Common exam trap

The CKAD exam often tests the distinction between `kubectl expose` (which creates a Service from an existing resource) and `kubectl create service` (which creates a standalone Service without a selector), leading candidates to pick Option A because they think 'create service' is the correct verb for making a Service.

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 --name=web-svc --port=80 --type=LoadBalancer

`kubectl expose deployment` creates a Service from an existing Deployment, and the `--name` flag sets the Service name to `web-svc`. The `--port=80` and `--type=LoadBalancer` flags configure the Service to listen on port 80 and expose it externally via a cloud load balancer, which is the standard way to create a LoadBalancer Service for a Deployment.

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 create service web-svc --port=80 --type=LoadBalancer

    Why it's wrong here

    The `kubectl create service` command creates a Service object without inferring the pod selector from an existing Deployment named `web`. The Service's selector defaults to labels based on the service name (e.g., `app=web-svc`) or remains empty, so it cannot route traffic to the Deployment's pods. Additionally, the provided flags are syntactically incorrect for `kubectl create service`, which requires a subcommand like `loadbalancer` and a `--tcp` flag rather than `--port` and `--type`. Therefore, this command does not properly expose the Deployment as a LoadBalancer Service.

  • ✓

    kubectl expose deployment web --name=web-svc --port=80 --type=LoadBalancer

    Why this is correct

    This is the correct command because `kubectl expose deployment web` reads the Deployment's pod template labels and automatically creates a Service whose selector matches those labels, ensuring the Service routes traffic to all pods managed by the Deployment. The `--type=LoadBalancer` flag requests an external load balancer from the cloud provider, `--name=web-svc` assigns a stable DNS name, and `--port=80` sets the Service's forward port. This is the standard imperative way to create a LoadBalancer Service that fronts a Deployment.

  • ✗

    kubectl create deployment web --expose --port=80 --type=LoadBalancer

    Why it's wrong here

    The `--expose` flag on `kubectl create deployment` does create a Service, but it always generates a ClusterIP Service, not a LoadBalancer, regardless of the `--type` flag. In fact, `--type` is not a valid option for `kubectl create deployment`, so the command would fail or ignore the unwanted flag entirely. Even if it did accept it, the resulting Service would be limited to cluster-internal access, not the external load-balanced exposure required.

  • ✗

    kubectl expose pod web --port=80 --type=LoadBalancer

    Why it's wrong here

    This command targets a Pod object named `web`, but the Deployment named `web` actually creates Pods with generated names like `web-12345-abcde`, so `kubectl expose pod web` would likely fail because that exact Pod name does not exist. If a standalone Pod named `web` did exist, exposing it directly would bind the Service to that single Pod's labels, bypassing the Deployment's selector and missing any scaling or updates. The correct method is to expose the Deployment, which ensures the Service's selector covers all current and future Pods managed by the Deployment.

About these practice questions

One of 826 original CKAD 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 →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKAD 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 CKAD exam.